Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by paularmstrong

I found a bug that was causing a crash in iOSImpact. I was trying to remove some buttons that I created, only to find the application would crash pretty quickly.

When using NSNotificationCenter and adding observers, you must always remove the observers when the the object that is listening to the notification is removed.

Here's the diff to fix:

diff --git a/Classes/lib/Impact/Canvas/JS_ScreenCanvas.m b/Classes/lib/Impact/Canvas/JS_ScreenCanvas.m
index 78b7db8..2fb7ca7 100755
--- a/Classes/lib/Impact/Canvas/JS_ScreenCanvas.m
+++ b/Classes/lib/Impact/Canvas/JS_ScreenCanvas.m
@@ -63,6 +63,7 @@ extern JS_Canvas * CanvasCurrentInstance;
 
 
 - (void)dealloc {
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
        [glview removeFromSuperview];
        [glview release];
        [super dealloc];

diff --git a/Classes/lib/Impact/JS_Button.m b/Classes/lib/Impact/JS_Button.m
index 52e22bc..a267d3c 100755
--- a/Classes/lib/Impact/JS_Button.m
+++ b/Classes/lib/Impact/JS_Button.m
@@ -95,6 +95,7 @@
 
 - (void)dealloc {
        // FIXME: Unprotect callbacks!?
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
        [button removeFromSuperview];
        [button release];
        [super dealloc];

diff --git a/Classes/lib/Impact/JS_iOSImpact.m b/Classes/lib/Impact/JS_iOSImpact.m
index 41e3fe6..2baae00 100755
--- a/Classes/lib/Impact/JS_iOSImpact.m
+++ b/Classes/lib/Impact/JS_iOSImpact.m
@@ -210,6 +210,7 @@ JS_GET(JS_iOSImpact, userAgent, ctx ) {
 
 
 - (void)dealloc {
+    [[NSNotificationCenter defaultCenter] removeObserver:self];
        [timers release];
        [super dealloc];
 }

1 decade ago by Jerczu

Weird I'm working with IOS atm except one memory leak I dont get any issues there. I didn't get to fix the mem leak yet - maybe its the same area as per your example will double check.
Page 1 of 1
« first « previous next › last »