Bug 19778 - UITableCellView is not GC collected if Superview property is called once
Summary: UITableCellView is not GC collected if Superview property is called once
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 7.2.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-05-14 14:37 UTC by Ievgen
Modified: 2014-05-14 21:41 UTC (History)
2 users (show)

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


Attachments
Example Solution to reproduce the problem (9.95 KB, application/zip)
2014-05-14 14:37 UTC, Ievgen
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:
RESOLVED NOT_REPRODUCIBLE

Description Ievgen 2014-05-14 14:37:13 UTC
Created attachment 6809 [details]
Example Solution to reproduce the problem

Actually I don't know if it's an expected behavior because there are tricks in monotouch with collecting unmanaged UI instances, but it seems like a memory leak to me.

So, I just created a UITableView and one of the cells needs to know the Frame of the parent table for some UI layout logic. If I call Superview property once anywhere in the cell, it will stuck in memory forever (not disposed).

I created a test solution to see it in action. There is a basic controller TableView where the table with three different kind of cells is initialized. By default if you run the app, you will see the list of the cells, on 'Clean Up' button click the table will be disposed. If you check the Application Log:

2014-05-14 11:27:10.317 TableCellMemoryLeak[62307:2403] MemoryLeakedCell disposed
2014-05-14 11:27:10.319 TableCellMemoryLeak[62307:2403] MemoryLeakedCell disposed
2014-05-14 11:27:10.320 TableCellMemoryLeak[62307:2403] MemoryLeakedCell disposed
2014-05-14 11:27:10.321 TableCellMemoryLeak[62307:2403] WorkaroundedCell disposed
2014-05-14 11:27:10.321 TableCellMemoryLeak[62307:2403] GenericCell disposed
2014-05-14 11:27:10.322 TableCellMemoryLeak[62307:2403] WorkaroundedCell disposed
2014-05-14 11:27:10.323 TableCellMemoryLeak[62307:2403] MemoryLeakedCell disposed
2014-05-14 11:27:10.323 TableCellMemoryLeak[62307:2403] MemoryLeakedCell disposed
2014-05-14 11:27:10.324 TableCellMemoryLeak[62307:2403] GenericCell disposed
2014-05-14 11:27:10.324 TableCellMemoryLeak[62307:2403] GenericCell disposed
2014-05-14 11:27:10.325 TableCellMemoryLeak[62307:2403] WorkaroundedCell disposed
2014-05-14 11:27:10.326 TableCellMemoryLeak[62307:2403] GenericCell disposed
2014-05-14 11:27:10.326 TableCellMemoryLeak[62307:2403] GenericCell disposed
2014-05-14 11:27:10.327 TableCellMemoryLeak[62307:2403] GenericCell disposed
2014-05-14 11:27:10.328 TableCellMemoryLeak[62307:2403] WorkaroundedCell disposed

You will see that the cells are properly disposed.

So, to reproduce the problem, the line 78 should be uncomment in MemoryLeakedCell class. After repeating the steps, the cells are not disposed on Cleaning Up the table. Actually I don't know why all cells are leaked in this example, in my application all normal cells are disposed expect the ones where Superview was accessed.

As a workaround in my app, I just save a WeakReference to parent that I get from WillMoveToSuperview() method. But I think it worths to check if indeed there are memory-leaks.

Thanks,
Comment 1 Sebastien Pouliot 2014-05-14 21:41:33 UTC
The "New RefCount" (NRC) feature solve this "retention" issue (where some instances were hard to release).

You can enable it on 7.2.1 (and later) for both Bohem or SGEN garbage collection. It's inside the Project options, under "iOS Build", "Advanced" (tab) and "Use the reference counting extension".

The release notes [1] has more information about the feature. We plan on making it the default in a future version of XI (but it's not something we wanted to do in a maintenance release).

[1] http://docs.xamarin.com/releases/ios/xamarin.ios_7/xamarin.ios_7.2/#1

note: the feature existed before 7.2.1 but only in SGEN and was substentially enhanced in 7.2.1