new-frame handler increasing retain count

Home Forums Syphon Syphon Development – Developer new-frame handler increasing retain count

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #6418
    nisar.med@gmail.com
    Participant

    I 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

    #6419
    vade
    Keymaster

    Random guess: try specifying “__unsafe_unretained __block SyphonClient* client” in the new frame handler?

    #6420
    nisar.med@gmail.com
    Participant

    Thanks 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.

    #6421
    bangnoise
    Keymaster

    Circumventing 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).

    #6423
    nisar.med@gmail.com
    Participant

    I 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];

     

    #6424
    bangnoise
    Keymaster

    Sorry 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.

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.