开发者

NSDate creating a memory leak

开发者 https://www.devze.com 2023-03-28 11:42 出处:网络
I was already browsing through the questions alreaded posted and there were a lot of hints I tried to work with. Unfortunately I don\'t get the issue solved.

I was already browsing through the questions alreaded posted and there were a lot of hints I tried to work with. Unfortunately I don't get the issue solved.

I simply have the following code:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSDate *date = [[NSDate alloc] init];
self.timestamp = date;
[date release];

[pool release];

But still th开发者_开发百科ere is a memory leak at the allocation line of NSDate. I tried it without the AutoreleasePool, I tried using drain instead of release for the pool, I even tried to use the static NSDate date methode. But I do not get rid of the memory leak.

I still don't get it. Any help is highly appreciated.


Write only

self.timestamp = [NSDate date];

instead of given code block,it will work without leak.


is [timestamp release] in your dealloc implementation? IE:

-(void)dealloc {
  // ... your other retained property/ivar releases ... //
  [timestamp release];
  [super dealloc];
}

Also, if you're running in a standard iOS project, you shouldn't need to set up an NSAutoreleasePool of your own (unless you're in a tight loop or a thread implementation).


Memory Management in ObjectiveC for iOS is just reference reference counting. If you find "Apple's Mem Management a bit daunting" then try this - "Simple Memory Management Tools for Cocoa"

0

精彩评论

暂无评论...
验证码 换一张
取 消