相关疑难解决方法(0)

Kotlin Bytecode - 如何在IntelliJ IDEA中进行分析?

我想看看编译后的字节码,这样我就可以了解它在封面下的工作原理.我正在使用IntelliJ IDEA 15,但找不到查看字节码的方法.我错过了什么?

intellij-idea kotlin android-studio jvm-bytecode

59
推荐指数
2
解决办法
7169
查看次数

Kotlin:安全的lambdas(没有内存泄漏)?

在阅读了关于内存泄漏的这篇文章之后,我想知道在Kotlin Android项目中使用lambdas是否安全.确实,lambda语法让我更容易编程,但内存泄漏怎么样?

作为问题的一个例子,我从我的一个项目中获取了一段代码,在那里我构建了一个AlertDialog.此代码位于项目的MainActivity类中.

fun deleteItemOnConfirmation(id: Long) : Unit {
        val item = explorerAdapter.getItemAt(id.toInt())
        val stringId = if (item.isDirectory) R.string.about_to_delete_folder else R.string.about_to_delete_file

        val dialog = AlertDialog.Builder(this).
                setMessage(String.format(getString(stringId), item.name)).setPositiveButton(
                R.string.ok, {dialog: DialogInterface, id: Int ->
                        val success = if (item.isDirectory) ExplorerFileManager.deleteFolderRecursively(item.name)
                        else ExplorerFileManager.deleteFile(item.name)
                        if (success) {
                            explorerAdapter.deleteItem(item)
                            explorerRecyclerView.invalidate()
                        }
                        else Toast.makeText(this@MainActivity, R.string.file_deletion_error, Toast.LENGTH_SHORT).show()
                    }).setNegativeButton(
                R.string.cancel, {dialog: DialogInterface, id: Int ->
                    dialog.cancel()
        })

        dialog.show()
}
Run Code Online (Sandbox Code Playgroud)

我的问题很简单:为正负按钮设置的两个lambdas可以导致内存泄漏吗?(我的意思是,kotlin lambdas只是转换为Java匿名函数吗?)

编辑:也许我在这个Jetbrains话题中得到了答案.

lambda android memory-leaks kotlin

28
推荐指数
3
解决办法
7810
查看次数