nikey
nikey

Reputation: 343

Memory Leaks in Class method objective -c

i had a problem with memory leak in this below code , potential leak of an object in line 39,

and here line 39 is ,[self alloc] init];

+ (UploaderThread *)sharedUploaderThread {
    @synchronized(self) {
        if (_sharedUploaderThread == nil) 
        {
            [[self alloc] init];

        }
    }
    return _sharedUploaderThread;
}

plz help me , wer i did the mistake

Upvotes: 0

Views: 180

Answers (3)

Andrew
Andrew

Reputation: 24866

You are not storing the pointer to the allocated object. Think you've ment:

_sharedUploaderThread = [[self alloc] init];

Upvotes: 1

Stephan van den Heuvel
Stephan van den Heuvel

Reputation: 2138

You never set _sharedUploaderThread equal to the [[self alloc] init]. Thereby leaking it.

Upvotes: 0

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

You are not assigning the value to _sharedUploaderThread. Do

_sharedUploaderThread = [[self alloc] init];

Since you were not assigning the value, you were leaking.

Upvotes: 2

Related Questions