Bug 26966 - Possible Memory Leak in CGBitmapContext()
Summary: Possible Memory Leak in CGBitmapContext()
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-02-11 16:14 UTC by Cody Beyer (MSFT)
Modified: 2015-02-12 06:22 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Cody Beyer (MSFT) 2015-02-11 16:14:42 UTC
### Description

The following example app rotates an image each time the button is clicked, and this appears to result in a memory leak

### Test Case

https://www.dropbox.com/s/9xnn93t2qyyvvdn/124229CGRotate.zip?dl=0

### Steps to reproduce

1. Open linked app
2. Deploy and connect with a profiler of your choice
3. Hit the rotate button 50+ times

### Expected Results

The image will rotate, which could cause a temporary memory rise, which will fall again after the rotation is complete

### Actual Results

The image rotates and the memory rises but never falls

### Screenshot of Test Cloud

https://www.dropbox.com/s/vdqzi263ucqz02l/Screenshot%202015-02-11%2013.03.42.png?dl=0

### Version

=== Xamarin Studio ===

Version 5.8 (build 408)
Installation UUID: 2408dd70-f3f8-4fbc-93e9-c239e5280118
Runtime:
	Mono 3.12.0 ((detached/de2f33f)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000076

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: 8.6.1.20 (Business Edition)
Hash: 3b3ef43
Branch: 
Build date: 2015-01-24 09:42:21-0500

=== Xamarin.Android ===

Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 1.10.0.18 (Business Edition)

=== Build Information ===

Release ID: 508000408
Git revision: b1d963f5d0cd149d573783298b1e65feb993fe75
Build date: 2015-02-06 17:39:40-05
Xamarin addins: cec3e3151b66f73570a21c3eb465eb7baa934f15

=== Operating System ===

Mac OS X 10.10.2
Darwin Codys-MBP.router 14.1.0 Darwin Kernel Version 14.1.0
    Mon Dec 22 23:10:38 PST 2014
    root:xnu-2782.10.72~2/RELEASE_X86_64 x86_64
Comment 1 Rolf Bjarne Kvinge [MSFT] 2015-02-12 06:22:02 UTC
When assigning to the UIImageView the previous image isn't disposed.

This makes the memory usage constant:

	using(done = context.ToImage ())
	{
		ImageToRotate.Image.Dispose (); // added
		ImageToRotate.Image = UIImage.FromImage (done);
	}

The GC would eventually free the images as well, but it takes a lot longer.