Bug 17213 - Memory Leak
Summary: Memory Leak
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: master
Hardware: PC Mac OS
: Normal normal
Target Milestone: 7.2.1
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-01-13 22:19 UTC by Belinda Pickering
Modified: 2014-03-21 14:23 UTC (History)
6 users (show)

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


Attachments
memory leak sample (7.48 MB, application/zip)
2014-01-13 22:36 UTC, Belinda Pickering
Details


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:
VERIFIED FIXED

Description Belinda Pickering 2014-01-13 22:19:16 UTC
Please see http://forums.xamarin.com/discussion/12270/memory-leak-possibly-with-uigraphics for related discussion. The attached sample project should just keep adding allocations until it eventually fails.
Comment 1 Belinda Pickering 2014-01-13 22:36:47 UTC
Created attachment 5833 [details]
memory leak sample

to make this sample work you will need to point it to an image at line 31 in MemoryLeakSampleViewController (var image = UIImage.FromBundle("zoo.jpg");) - the file was too large to attach with an image in it.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2014-01-14 07:33:43 UTC
The issue is that some of the image-related objects that are created for each timer tick is placed onto an NSAutoreleasePool, and that pool is never drained.

We create an NSAutoreleasePool for every thread, and that pool is drained when the thread finishes, but the timer ticks all occur on the same thread, so the automatically created NSAutoreleasePool is never drained.

The fix you can implement is to surround the code in the timer's Elapsed handler with an NSAutoreleasePool:

    timer.Elapsed += ...
    {
        using (var pool = new NSAutoreleasePool ()) {
            IosImageManipulator manipulator = new IosImageManipulator();
            ...
        }
    };

I'll fix Xamarin.iOS so that in future versions this will become unnecessary.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2014-01-14 08:06:37 UTC
Fixed.

monotouch/master: 1fd4cee0de996be161c6599fd4ec535351e0cacd
Comment 4 Udham Singh 2014-03-20 11:49:18 UTC
I have checked this issue with latest builds and I am still getting memory leak
with attached sample 'memory leak sample' in comment 1.

Screencast: http://screencast.com/t/5O66oqF5vR1W

=== Xamarin Studio ===

Version 4.2.4 (build 32)
Installation UUID: b1fc3b76-cf00-405e-a0a1-3839ac11fe6d
Runtime:
    Mono 3.2.7 ((no/40f92d5)
    GTK+ 2.24.23 (Raleigh theme)

    Package version: 302070000

=== Apple Developer Tools ===

Xcode 5.1 (5051.4)
Build 5B90f

=== Xamarin.Mac ===

Xamarin.Mac: 1.8.0.7

=== Xamarin.iOS ===

Version: 7.2.1.20 (Enterprise Edition)
Hash: 7342842
Branch: 
Build date: 2014-03-18 18:20:49-0400

=== Build Information ===

Release ID: 402040032
Git revision: a160c35dac9ab9fd32eeadaa171216316d5a5133
Build date: 2014-03-12 13:55:08-04
Xamarin addins: a779416ceabd54981ce812771a4061c942e8b872

=== Operating System ===

Mac OS X 10.9.3
Darwin Apples-iMac.local 13.2.0 Darwin Kernel Version 13.2.0
    Tue Mar 11 22:16:58 PDT 2014
    root:xnu-2422.100.4~2/RELEASE_X86_64 x86_64
Comment 5 Sebastien Pouliot 2014-03-21 08:29:45 UTC
@Udham Singh, it should be clear from the description that what you're seeing [1] (screencast from comment #4) is unrelated to the original bug report [2].

IOW that's a different issue, unrelated to the sample code, and needs a separate bug report (you can give a link to this so the same app/screencast can be re-used).

note: re-opening bug should only be done for regressions (not for similar. but unrelated, issues)

[1] a single NSAutoreleasePool
[2] multiple UIImage
Comment 6 Udham Singh 2014-03-21 11:04:33 UTC
I have checked this and implemented the code given in comment 2 with the sample project provided in comment 1 for a single image as well as multiple images. I am not seeing any memory leak related image objects. 

Screencast: http://screencast.com/t/IewffZYcQ1T

However getting memory leak for NSAutoreleasePool object and filed a separate bug 18505 for this.
Comment 7 Udham Singh 2014-03-21 14:23:34 UTC
I have checked this issue with sample project provided in comment 1 without modifying the code and it is working fine without any memory leak.

Screencast: http://screencast.com/t/GyQbo20xZ

Environment Info:

Mac 10.9.3
Xamarin Studio : 4.2.4 (build 32)
Xamarin.iOS : 7.2.1.22 (Enterprise Edition)


As per my observation I am not getting any memory leak related to image object either I checked this issue with the sample project given into the comment 1 or with modified code for a single image as well as multiple images. I am getting memory leak for NSAutoreleasePool only and filed a separate bug for the same as mentioned in comment 6. So I am closing this issue.