Detecting memory leaks
A memory leak is a condition when the memory used by an object isn’t released when that object is no longer needed. Memory leaks can lead to significant performance issues and faster battery drain.
Identifying objects that remain in memory can be challenging without the right tools. Similar to performance profiling, Visual Studio doesn’t provide functionality to diagnose memory leaks on Android and iOS. However, we can utilize nearly the same set of tools as in the previous recipe: VS Code, the .NET Meteor extension, and an additional extension called Heapview.
Before diving into memory profiling, let’s briefly discuss the basics of memory management in .NET. Managed memory is handled by the garbage collector (GC), which takes care of both memory allocation and deallocation when objects are no longer in use. Memory allocated to an object can only be reclaimed if no strong references to it exist from other active objects. For example...