• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Posting MainThread Runnables Memory Leak Safe Android

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I have a question regarding memory leaks. I have the below anonymous class. As you might know anonymous class hold reference from the outside object(here is Activity). Does this code causes memory leak or not? In case of orientation this will hold the old activity. Right?

Thank you

public class MainActivity extends AppCompatActivity{

 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would seem that the class is done with quickly, so I'm not sure what would be in danger of being leaked.
 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Somewhat related, if you were to switch to using Kotlin for Android development and then used the co-routines you may find it easier to do hand thread related operations like the one you posted without the fear of memory leakage.
The Google keywords for this would be kotlin android coroutines.

By the way, you can use Kotlin source files and Java source files in the same Android project. This may help with your migration to Kotlin.
 
reply
    Bookmark Topic Watch Topic
  • New Topic