Jongers
Jongers

Reputation: 691

Objective-C Passing address of non-local object to __autoreleasing parameter

How can I change this line of code [NgnAVSession releaseSession: &audioSession]; so that I will no longer get this error:

Passing address of non-local object to __autoreleasing parameter for write-back

this is the whole method

- (void)viewWillDisappear:(BOOL)animated
{
    [NgnAVSession releaseSession: &audioSession];
    [UIDevice currentDevice].proximityMonitoringEnabled = NO;
}

Here is the declaration of releaseSession

Header

+(void) releaseSession: (NgnAVSession**) session;

Implementation

+(void) releaseSession: (NgnAVSession**) session{
        @synchronized (kSessions){
            if (session && *session){
                if([(*session) retainCount] == 1){
                    [kSessions removeObjectForKey:[*session getIdAsNumber]];
                }
                else {
                    [(*session) release];
                }
                *session = nil;
            }
        }
    }

Upvotes: 0

Views: 414

Answers (1)

gnasher729
gnasher729

Reputation: 52538

You are using a very old library. Try getting a newer version.

Then read up how Cocoa use NSError*. You really need to do this, because otherwise you cannot possibly understand what's going on.

Long story short: The compiler assumes that you pass the address of an autoreleasing variable. If needed it can turn a local variable into an autoreleasing one. That cannot be done with a non-local variable.

What these guys are doing is just wrong, wrong, wrong, wrong, wrong. If they want to keep track of all sessions without counting references, the easiest way is to create a wrapper object holding a weak reference, putting the wrapper objects into the array, and in the dealloc method you can remove the object from the array.

I'd suggest that you throw away their releaseSession and do exactly what I said before.

Upvotes: 1

Related Questions