Everything you need to know about Memory Leaks in android.

<p>One of the core benefits of Java, or to be more accurate, of the JVM (Java Virtual Machine)<strong>,&nbsp;</strong>is the garbage collector (GC). We can create new objects without worrying about freeing them up from memory. The garbage collector will take care of allocating and freeing up the memory for us.</p> <p><strong>We won&rsquo;t have to worry about freeing allocated objects because the garbage collector will allocate and free memory for us?</strong>&nbsp;Definitely not! We should be concerned without a solid understanding of how the garbage collector works, we can prevent it from freeing memory, resulting in memory leaks that can lead to out-of-memory exceptions and lags in the app.</p> <p><strong>What is Memory Leak?</strong></p> <blockquote> <p>Failure to release&nbsp;<em>unused objects from the&nbsp;</em>memory</p> </blockquote> <p>Failure to release&nbsp;<em>unused objects from the&nbsp;</em>memory means that there are unused objects in the application that the GC cannot clear from memory.</p> <p>When the garbage collector (GC) fails to remove unused objects from memory. The memory unit that holds the unused objects will be occupied until the end of the application or method (depends on the scenario).</p> <h2>Memory Leaks: Temporary vs Permanent</h2> <p>Leaks can be divided into two categories: those that occupy the memory unit until the&nbsp;<strong>application terminates (permanent)&nbsp;</strong>and those that occupy the memory unit until the&nbsp;<strong>method terminates (temporary)</strong>.</p> <p>The first category, application terminations (permanent), is self-evident: when an app is terminated, the GC releases all of the memory that the app has used.</p> <p>The second category, method terminations (temporary), requires a little more explanation; for a better understanding, let&rsquo;s use an example.</p> <p><a href="https://proandroiddev.com/everything-you-need-to-know-about-memory-leaks-in-android-d7a59faaf46a">Visit Now</a></p>
Tags: Android Leaks