Home › Forums › Syphon › Syphon Development – Developer › new-frame handler increasing retain count
- This topic has 5 replies, 3 voices, and was last updated 8 years, 4 months ago by
bangnoise.
-
AuthorPosts
-
October 24, 2012 at 9:17 am #6418
nisar.med@gmail.com
ParticipantI have been using SyphonQC plugin but now I want to change it and use the new-frame handler so I can manage frames more accurately.
changes in the function
– (void)setClientFromSearchHavingLock:(BOOL)isLocked
are….//newClient = [[SyphonClient alloc] initWithServerDescription:[matches lastObject] options:nil newFrameHandler:nil];
newClient = [[SyphonClient alloc] initWithServerDescription:[matches lastObject] options:nil newFrameHandler:^(SyphonClient *client) {
CGLContextObj cgl_ctx = [_context CGLContextObj];
SyphonImage* image = [[client newFrameImageForContext:cgl_ctx] autorelease];
if(image)
[_frameQueue insertObject:image atIndex:0];
}];
This piece of code increases retain count of the “self” object so I am unable to release it on stopExecution function of the Plugin. I don’t know why is it happening despite trying to understand it several times 🙂Thanks
October 24, 2012 at 10:28 am #6419vade
KeymasterRandom guess: try specifying “__unsafe_unretained __block SyphonClient* client” in the new frame handler?
October 24, 2012 at 11:17 am #6420nisar.med@gmail.com
ParticipantThanks actually it was a retain cycle issue and the solution is to use blockSelf->ivar to access all variables inside the block
__block SyphonNameboundClient *blockSelf = self;
Strange, I didn’t observe this issue in the Test Client Sample.October 24, 2012 at 1:05 pm #6421bangnoise
KeymasterCircumventing the retain rather misses the point – you don’t want your object being released while the block is still executing.
As a note, once you call -stop on the client, the handler is released (and with it, anything it retained).
October 25, 2012 at 12:25 am #6423nisar.med@gmail.com
ParticipantI tried, but stop only removed the frame handler which did not release the object it retained hence syClient dealloc is never called.
Inside stopExecution
[syClient lockClient];
[syClient.client stop];
[syClient unlockClient];
[syClient release];October 25, 2012 at 5:07 am #6424bangnoise
KeymasterSorry yea, I was wrong – stop doesn’t release the handler.
What I do in such cases is create a container object which has everything the handler needs to function which the handler and the client can both retain without causing a retain loop.
-
AuthorPosts
- You must be logged in to reply to this topic.