TChart is not collcted by gc in xamrin.ios
Posted: Tue Jun 26, 2018 9:31 am
in class TChart,
there is such code:
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:
ref:
https://developer.apple.com/documentati ... tification
there is such code:
Code: Select all
protected void initVars()
{
...
NSNotificationCenter.DefaultCenter.AddObserver((NSString)"UIDeviceOrientationDidChangedNotification",
delegate {
this.chart.Invalidate();
});
...
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);
}
https://developer.apple.com/documentati ... tification