Reputation: 3240
When i running my app output shows me a lot of this strings:
2012-05-12 14:41:52.542 PermTour[1688:15c0b] *** __NSAutoreleaseNoPool(): Object 0x5c39520 of class NSCFString autoreleased with no pool in place - just leaking
And i know that the problem in this part of code. Because, when i comment it, output is empty.
for(int i=0;i<[dataBase.allDataBase count];i++){
aPLace = [dataBase.allDataBase objectAtIndex:i];
name = [aPLace.name lowercaseString];
description = [aPLace.description lowercaseString];
if (!([name rangeOfString:searchText].location == NSNotFound) || !([description rangeOfString:searchText].location == NSNotFound)){
[foundedPlaces addObject:aPLace];
}
}
Any ideas? Thnx
UPD.
When i comment all code and it looks like:
for(int i=0;i<[dataBase.allDataBase count];i++){
aPLace = [dataBase.allDataBase objectAtIndex:i];
name = [aPLace.name lowercaseString];
//description = [aPLace.description lowercaseString];
/*
if (!([name rangeOfString:searchText].location == NSNotFound) || !([description rangeOfString:searchText].location == NSNotFound)){
[foundedPlaces addObject:aPLace];
}
*/
}
Still memory leaking.. So what you think write now?
UPD 2
Upvotes: 0
Views: 542
Reputation: 122458
I have seen this error message is class initialisation methods (for example +initialize
, +load
or other custom methods).
The solution for me was simply to create an autorelease pool, like this:
@autoreleasepool
{
initThis();
[That init];
}
The @autoreleasepool
keyword may be used in both ARC and non-ARC projects with similar semantics.
Here is the small print on the matter:
The NSApplication class sets up autorelease pools (instances of the NSAutoreleasePool class) during initialization and inside the event loop—specifically, within its initialization (or sharedApplication) and run methods. Similarly, the methods the Application Kit adds to NSBundle employ autorelease pools during the loading of nib files. These autorelease pools aren’t accessible outside the scope of the respective NSApplication and NSBundle methods. Typically, an application creates objects either while the event loop is running or by loading objects from nib files, so this lack of access usually isn’t a problem. However, if you do need to use Cocoa classes within the main() function itself (other than to load nib files or to instantiate NSApplication), you should create an autorelease pool before using the classes and then release the pool when you’re done. For more information, see NSAutoreleasePool in the Foundation Framework Reference.
Upvotes: 1
Reputation: 11839
When you are dealing with a lot of data(memory), then it is always preferable to use NSAutoreleasePool
.
EDIT -
-(returnType)yourMethod:(returnType)parameter @autoreleasepool
{
@autoreleasepool
{
//method body.
}
}
Hope this will help you.
Upvotes: 2