diff --git a/Audio/CogDecoderMulti.m b/Audio/CogDecoderMulti.m index 4ccfeb1b8..4d55bc9a2 100644 --- a/Audio/CogDecoderMulti.m +++ b/Audio/CogDecoderMulti.m @@ -49,11 +49,17 @@ }]; theDecoders = sortedDecoders; theDecoder = nil; - cachedObservers = [[[NSMutableArray alloc] init] autorelease]; + cachedObservers = [[NSMutableArray alloc] init]; } return self; } +- (void)dealloc +{ + [cachedObservers release]; + [super dealloc]; +} + - (NSDictionary *)properties { if ( theDecoder != nil ) return [theDecoder properties]; @@ -97,6 +103,9 @@ { if ( theDecoder != nil ) { [theDecoder close]; + for (NSDictionary *obsItem in cachedObservers) { + [theDecoder removeObserver:[obsItem objectForKey:@"observer"] forKeyPath:[obsItem objectForKey:@"keyPath"]]; + } [theDecoder release]; theDecoder = nil; } @@ -114,14 +123,14 @@ [cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", options, @"options", context, @"context", nil]]; } +/* And this is currently called after the decoder is closed */ - (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath { - if ( theDecoder != nil ) - [theDecoder removeObserver:observer forKeyPath:keyPath]; for (NSDictionary *obsItem in cachedObservers) { if ([obsItem objectForKey:@"observer"] == observer && [keyPath isEqualToString:[obsItem objectForKey:@"keyPath"]]) { [cachedObservers removeObject:obsItem]; + break; } } }