Please advise on memory handling
Please advise on memory handling
- Subject: Please advise on memory handling
- From: "Gurmit Teotia" <email@hidden>
- Date: Wed, 7 Jun 2006 19:31:55 +0530
Hi All,
My application behave somewhat like VNC server. It receive mouse and
keyboards events and generate them on local machine. I'm adding
receiving events in NSMutableString object before processing them.
Following method is called to add the event to NSMutableString object:
-(void)addEvent:(NSString *)event
{
NSLog(@"<PVRemoteEventSimulator>Simulating the event %@",event);
[conditionLock lock];
[eventBuffer appendString:event]; //eventBuffer is NSMutableString object
[conditionLock unlockWithCondition:NONEMPTY];
}
I've create another thread to read the event information from this
NSMutableString, which methods look somewhat like this:
-(void)handleEvents:(id)anObject
{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
NSRange range;
while(!isFinished)
{
//Wait on lock to get the event information.
[conditionLock lockWhenCondition:NONEMPTY];
if(isFinished)
{
break;
}
//event information is terminated by \n
range=[eventBuffer rangeOfString:@"\n"];
//Get the event
NSString *event=[eventBuffer substringWithRange:range];
//seperate the event information like, mouse down/up ,x,y
co-ordinates.
NSArray *arr=[event componentsSeparatedByString:@"|"];
.............
//Generate the event
//Remove event from eventBuffer
//Set lock condition(empty or notempty)
}
[pool release];
}
Now "while loop" in above method may be called around 1024(may be some
less) times by simply moving the mouse across screen. NSString and
NSArray object returns by methods "substringWithRange" and
"componentsSeperatedByString" are added to autorelease pool. Because
these objects are not freed so after running for a while these objects
will increase the memory footprint of my application. If I create and
release the autorelease pool inside "while loop" then it may affect
the performance of application.
Could someone please suggest the right approach for above problem?
Regards,
Gurmit
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden