Reader small image

You're reading from  Xamarin 4.x Cross-Platform Application Development - Third Edition

Product typeBook
Published inDec 2016
Reading LevelIntermediate
Publisher
ISBN-139781786465412
Edition3rd Edition
Languages
Tools
Right arrow
Author (1)
Jonathan Peppers
Jonathan Peppers
author image
Jonathan Peppers

Jonathan Peppers is a Xamarin MVP and lead developer on popular apps and games at Hitcents such as the Hanx Writer (for Tom Hanks) and the Draw a Stickman franchise. Jon has been working with C# for over 10 years working on a wide range of projects at Hitcents. Jon began his career working Self-Checkout software written in WinForms and later migrated to WPF. Over his career, he has worked with many .NET-centric technologies such as ASP.Net WebForms, MVC, Windows Azure, WinRT/UWP, F#, and Unity3D. In recent years, Hitcents has been heavily investing in mobile development with Xamarin, and has development over 50 mobile applications across multiple platforms.
Read more about Jonathan Peppers

Right arrow

Avoiding common memory pitfalls


Memory on mobile devices is certainly not an unlimited commodity. Because of this, memory usage in your application can be much more important than on desktop applications. At times, you might find the need to use a memory profiler or improve your code to use memory more efficiently.

The following are the most common memory pitfalls:

  • The garbage collector (GC) is unable to collect large objects fast enough to keep up with your application

  • Your code inadvertently causes a memory leak

  • A C# object is garbage collected, but is later attempted to be used by native code

Let's take a look at the first problem, where the GC cannot keep up. Let's say we have a Xamarin.iOS application with a button for sharing an image on Twitter, as follows:

twitterShare.TouchUpInside += (sender, e) => 
{ 
  var image = UImage.FromFile("YourLargeImage.png"); 
  //Share to Twitter 
}; 

Now let's assume the image is a 10 MB image from the user's camera roll. If...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Xamarin 4.x Cross-Platform Application Development - Third Edition
Published in: Dec 2016Publisher: ISBN-13: 9781786465412

Author (1)

author image
Jonathan Peppers

Jonathan Peppers is a Xamarin MVP and lead developer on popular apps and games at Hitcents such as the Hanx Writer (for Tom Hanks) and the Draw a Stickman franchise. Jon has been working with C# for over 10 years working on a wide range of projects at Hitcents. Jon began his career working Self-Checkout software written in WinForms and later migrated to WPF. Over his career, he has worked with many .NET-centric technologies such as ASP.Net WebForms, MVC, Windows Azure, WinRT/UWP, F#, and Unity3D. In recent years, Hitcents has been heavily investing in mobile development with Xamarin, and has development over 50 mobile applications across multiple platforms.
Read more about Jonathan Peppers