I have been doing Java development for a long time, but I am ashamed to say I still don't have a good grasp on how memory leaks actually takes place. I however have no experience with Android development.
Take the following code for example taken from this presentation:
I have the following questions (please note that I am new to Android, but this example is not primarily focused on Android)
How is memory leak even possible here ? The author says that its because the inner class is not marked as static and it will hold a reference to the outer class.
So if I keep creating objects of the outer class like so:
MainActivity one = new MainActivity();
one.onCreate(bundle);
MainActivity two = new MainActivity();
two.onCreate(bundle);
MainActivity three = new MainActivity();
three.onCreate(bundle);
How does it matter ? If I am not wrong about how static references work, then only one object of LeakClass is created, right ? Unless a separate classloader is involved, right ?
Is the memory leak only possible here because of how Android works ? If I were to manually create these objects then this would not be a problem right ?
Please help me with an ELI5 explanation here, I am really unable to understand how this works.
Thanks.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)