Bug 15081 - Using NSImage.Dispose() causes a serious memory leak
Summary: Using NSImage.Dispose() causes a serious memory leak
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.6.9
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Chris Hamons
Depends on:
Reported: 2013-09-30 17:25 UTC by Curtis Wensley
Modified: 2014-12-03 16:18 UTC (History)
2 users (show)

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

Reproduces the memory leak (21.49 KB, application/zip)
2013-09-30 17:25 UTC, Curtis Wensley

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:

Description Curtis Wensley 2013-09-30 17:25:24 UTC
Created attachment 5026 [details]
Reproduces the memory leak

Calling Dispose() on an NSImage (to free up its memory) does not work, and leaves the image data in memory.

It seems like there have been recent changes to the way Dispose/Finalizers work, and it does not seem to function correctly.

The attached sample can demonstrate the scenario that I am running into, where we are creating the NSImage, drawing it, then disposing it.

NOT calling dispose eventually frees up the memory when it is garbage collected, but this is not an option as the image data takes up a large chunk of memory and causes the memory usage to fluctuate quite drastically in the application.
Comment 1 Chris Hamons 2014-12-03 16:18:27 UTC
Hey Curtis,

Sorry for the unacceptably long delay in respond. We're working on being better at that in the future. This appears to be fixed on my local build. I can hold down space bar and the memory usage quickly levels off.

Please reopen if you run into this (or have another scenario that can reproduce.