![]() ![]() Now, in your example you are not assigning your Activity to some static variable, there're no Kotlin's objects involved which could keep your Activity from being garbage-collected - all the objects involved in your code have roughly the same lifetime, which means there will be no memory leaks. The simplest example is storing the reference to the Activity in the static variable (I'm talking from the Java perspective, but it's similar in Kotlin): after the user has clicked on 'Back' button the Activity is not needed anymore, but it will be kept in memory nevertheless - because some static variable still points to this activity. Memory leaks happen when some object which should be removed because it isn't needed anymore can not be removed because something which has a longer lifetime has a reference to this object. ![]() fun deleteItemOnConfirmation(id: Long) : Unit This code is inside the MainActivity class of my project. It's true that lambda syntax makes me program with more ease, but what about the Memory Leaks ?Īs an example of the problematic, I've taken a piece of code from one of my projects, where I build an AlertDialog. After having read this article about Memory Leaks, I am wondering whether using lambdas in Kotlin Android project is safe.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |