Bug 33240 - IOS ListViewRenderer.Dispose() should dispose header and footer
Summary: IOS ListViewRenderer.Dispose() should dispose header and footer
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 1.5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Rui Marinho
Depends on:
Reported: 2015-08-19 21:44 UTC by 3803657
Modified: 2016-04-21 11:06 UTC (History)
5 users (show)

Tags: ac
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:

Description 3803657 2015-08-19 21:44:37 UTC
Here is decompiled Xamarin.Forms.Platform.iOS.ListViewRenderer.Dispose() from Forms 1.5(1.4 is the same).
It just dispose viewTableCell, I think it should also dispose uiView itself in the loop, or there will be memory leak.

protected override void Dispose(bool disposing)
	if (disposing && this.insetTracker != null)
		this.insetTracker = null;
		Stack<UIView> stack = new Stack<UIView>(this.Subviews);
		while (stack.get_Count() > 0)
			UIView uIView = stack.Pop();
			ViewCellRenderer.ViewTableCell viewTableCell = uIView as ViewCellRenderer.ViewTableCell;
			if (viewTableCell != null)
				//SHOULD CALL: uIView.Dispose();
				UIView[] subviews = uIView.Subviews;
				for (int i = 0; i < subviews.Length; i++)
					UIView uIView2 = subviews[i];
		if (base.Element != null)
			base.Element.TemplatedItems.CollectionChanged -= new NotifyCollectionChangedEventHandler(this.OnCollectionChanged);
			base.Element.TemplatedItems.GroupedCollectionChanged -= new NotifyCollectionChangedEventHandler(this.OnGroupedCollectionChanged);
Comment 1 Simon Taylor 2015-09-23 04:38:51 UTC
It's also not disposing the private footerRenderer or headerRenderer properties.
Comment 2 Simon Taylor 2015-09-24 00:08:01 UTC
Also, in ListViewRenderer.UpdateHeader() and UpdateFooter() the MeasureInvalidated event handler is not unregistered when setting the header or footer to null when it was previously set. The handler is unregistered when setting the header or footer to a new view.

	if (this.headerRenderer != null)
                // I think it needs something like this.
                if (this.headerRenderer.Element != null)
                    this.headerRenderer.Element.MeasureInvalidated -= this.OnHeaderMeasureInvalidated;

		base.Control.TableHeaderView = null;
		this.headerRenderer = null;
Comment 3 Rui Marinho 2016-01-28 13:26:05 UTC
Should be fixed in 2.2.0-pre1
Comment 4 Rajneesh Kumar 2016-04-21 11:06:25 UTC
Hi, I to verify this issue, I have tried to reproduce this but not able to reproduce this. Could you please share a small sample application that demonstrate this issue. That would be very helpful to reproduce/verify this issue at our end.