Bug 33240

Summary: IOS ListViewRenderer.Dispose() should dispose header and footer
Product: Forms Reporter: 3803657
Component: iOSAssignee: Rui Marinho <rui.marinho>
Status: RESOLVED FIXED    
Severity: normal CC: 3803657, david, Rajneeshk, rui.marinho, staylr
Priority: ---    
Version: 1.5.0   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS   
Tags: ac Is this bug a regression?: ---
Last known good build:

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.Dispose();
		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)
			{
				viewTableCell.Dispose();
			}
			else
			{
				//SHOULD CALL: uIView.Dispose();
				UIView[] subviews = uIView.Subviews;
				for (int i = 0; i < subviews.Length; i++)
				{
					UIView uIView2 = subviews[i];
					stack.Push(uIView2);
				}
			}
		}
		if (base.Element != null)
		{
			base.Element.TemplatedItems.CollectionChanged -= new NotifyCollectionChangedEventHandler(this.OnCollectionChanged);
			base.Element.TemplatedItems.GroupedCollectionChanged -= new NotifyCollectionChangedEventHandler(this.OnGroupedCollectionChanged);
		}
	}
	base.Dispose(disposing);
}
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.Dispose();
		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.

Thanks..!