I’m using this fork of AudioStreamer to stream audio.
In a view controller I have an AudioStreamer as a property:
@property (nonatomic, retain) AudioStreamer *streamer
When the view controller loads I start a stream like this:
self.streamer = [[AudioStreamer alloc] initWithURL:[NSURL URLWithString:preset.url]];
And to stop the stream, release it, and start a new stream I’m doing this:
[streamer stop];
[streamer release];
self.streamer = nil;
self.streamer = [[AudioStreamer alloc] initWithURL:[NSURL URLWithString:preset.url]];
This doesn’t work because in the initWithURL: method, there’s a check to see if (self != nil) and that check fails.
Would anyone be able to clarify why this isn’t working?
Thanks.
EDIT: It was actually some issues with my project that was causing weird issues. However, I marked an answer as correct because it had some good memory tips that also helped.
You are overretaining the streamer instance by setting it with the dot syntax and using alloc.
The synthesized setter will retain it once and alloc the second time, you should add an autorelease:
This line:
Will automatically release the previously assigned instance for you. So you don’t have to call
before it.
However you should do
in your dealloc method.