TChart is not collcted by gc in xamrin.ios

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
bill2004158
Newbie
Newbie
Posts: 1
Joined: Thu Mar 01, 2018 12:00 am

TChart is not collcted by gc in xamrin.ios

Post by bill2004158 » Tue Jun 26, 2018 9:31 am

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
Last edited by bill2004158 on Fri Jun 29, 2018 11:34 am, edited 1 time in total.

Pep
Site Admin
Site Admin
Posts: 3295
Joined: Fri Nov 14, 2003 5:00 am
Contact:

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

Post by Pep » Wed Jun 27, 2018 2:01 pm

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.

Post Reply