Re: MOKit memory problem
Re: MOKit memory problem
- Subject: Re: MOKit memory problem
- From: Marcel Weiher <email@hidden>
- Date: Mon, 12 Aug 2002 15:58:34 +0200
You are creating lots of autoreleased MORegularExpressionObjects each
time this method is invoked. As long as the current autorelease-pool
isn't released, these will stick around.
Solutions:
1. Get the autoreleased instances released
The easiest way to do this is probably to create an autorelease-pool at
the start of your method and release it at the end.
The one thing you have to be careful about is the dictionary you are
creating, which you do NOT want to release just yet. So:
- (NSDictionary *)parse:(NSString *)string
{
pool = [[NSAutoreleasePool alloc] init];
... your code to parse the strings
... your code to create the dictionary
[dictionary retain]; // make sure the dictionary survives the next line
[pool release]; // temps are now gone!
return [dictionary autorelease];
}
This should solve your problem, unless there really are leaks in MOKit
(which I doubt, somehow).
2. Avoid needles creation of instances
If the regular expressions are actually constant, it might be even
better to create them once, store them in your object's instance
variables and then reuse them as needed.
Marcel
On Monday, August 12, 2002, at 09:30 Uhr, Nico wrote:
Here's the code I use :
- (NSDictionary *)parse:(NSString *)string
{
NSString *myInfo1, *myInfo2;
MORegularExpression *regexp;
if ([[MORegularExpression regularExpressionWithString:@".* some RE
.*?
:.*"] matchesString:string])
{
regexp = [MORegularExpression regularExpressionWithString:@"(.*)
some
RE (.*?) :(.*)"];
myInfo1 = [regexp substringForSubexpressionAtIndex:1
inString:string];
myInfo2 = [regexp substringForSubexpressionAtIndex:2
inString:string];
} else if ... // here I verify whether the string matches another
regexp
{
} else if ... {
// etc..
}
// i return an NSDictionary* created using the strings (myInfo1
and/or
myInfo2, and many others)
}
(regexp is used only is the currend method, which is called each time
a new
data is read from a socket. This method is used to match what kind of
info
we've just retrieved from an IRC server)
MallocDebug indicates the major part of the memory is allocated for
MORegularExpression.
Please tell me if I didn't something *WRONG* :]
Thanks you :>
Nico
On 12/08/02 3:30, "Brock Brandenberg" <email@hidden> wrote:
Hundreds? It certainly isn't a lightweight class, so it's
understandable
that it will use RAM. How are you using the regex objects? Are you
keeping
hundreds around for the life of the program or are you creating,
using, and
releasing numerous times?
Brock
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.