Page 1 of 1

TChart is not collcted by gc in xamrin.ios

Posted: Tue Jun 26, 2018 9:31 am
by 18383107
in class TChart,
there is such code:

Code: Select all

    protected void initVars()
    {
...
NSNotificationCenter.DefaultCenter.AddObserver((NSString)"UIDeviceOrientationDidChangedNotification",
				delegate {
				this.chart.Invalidate();
			});
...
that code has two problems:
1. "UIDeviceOrientationDidChangedNotification" should be "UIDeviceOrientationDidChangeNotification"
2. added observer, when init, however, haven't unregister it when dispose this object. thus DefaultCenter will always refer to the delegate method, which caused gc will not collect the Tchart object. I think it should be like this:

Code: Select all

private readonly NSObject notification;

    protected void initVars()
    {
...
notification = NSNotificationCenter.DefaultCenter.AddObserver((NSString)"UIDeviceOrientationDidChangeNotification",
				delegate {
				this.chart.Invalidate();
			});
...
  }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                notification.Dispose();
            }

            base.Dispose(disposing);
        }

ref:
https://developer.apple.com/documentati ... tification

Re: TChart is not collcted by gc in xamrin.ios

Posted: Wed Jun 27, 2018 2:01 pm
by Pep
Hello,

thanks for the advise. You're correct, Let me recheck the latest source code, and do the modifications to fix these bugs for the next maintenance release.