Before you begin

This is a cross-platform class which primarily focuses on Xamarin.Android and Xamarin.iOS. To fully complete the coding exercises, you will need both development environments with either a simulator/emulator or devices to run the exercise on. Please see the setup page if you need help installing the Xamarin development environment.

Overview

In this class, we will look at specific techniques to identify memory issues in our managed applications and then turn to specific Xamarin.iOS and Xamarin.Android issues that many applications encounter.

Objectives

  1. Identify and fix memory leaks in your code
  2. Recognize and fix Xamarin.iOS specific memory problems
  3. Recognize and fix Xamarin.Android specific memory problems

Lecture

XAM370 - Diagnosing Memory Management Issues.

Exercises

Exercise materials are available from GitHub. The code can be cloned through a desktop Git client or downloaded directly as a ZIP file.

  1. Using the Xamarin Profiler to monitor allocations
    Demonstration
    In this demonstration, we will examine an application and watch it's memory allocation to identify some potential improvements we can make in the code.
  2. Finding and fixing delegate reference leaks
    Exercise
    In this exercise, we will track down a memory leak in a Xamarin.Forms application which is caused by an event handler.
  3. Identifying and breaking strong reference cycles
    Exercise
    In this group exercise, we will troubleshoot and fix a Xamarin.iOS application which has a reference cycle that causes a memory leak.
  4. Watch out for peer promotions
    Exercise
    In this group exercise, we will fix a case where Xamarin.iOS holds onto a view reference due to a framework peer promotion.
  5. Show ListView memory and performance with a custom adapter
    Demonstration
    In this final demonstration, we will troubleshoot and fix some performance issues with an Android application which utilizes a ListView.

Additional resources

iOS App Maximum Memory Memory and Performance Best Practices Android Performance Tips Working With SGen Android Profiler in Android Studio Tips for Creating a Smooth and Fluid Android UI A Journey of Hunting Memory Leaks in Xamarin