Re: Please advise on memory handling
Re: Please advise on memory handling
- Subject: Re: Please advise on memory handling
- From: "Gurmit Teotia" <email@hidden>
- Date: Thu, 8 Jun 2006 12:14:27 +0530
Thanks Shawn. Infect I was also thinking of release inner pool after some
iterations. But I want to confirm that I'm not going in wrong direction.
Thanks again.
Regards,
Gurmit
On 6/7/06, Shawn Erickson <email@hidden> wrote:
On Jun 7, 2006, at 7:01 AM, Gurmit Teotia wrote:
> 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.
Correct so if you want to minimize this foot print you can use an
inner autorelease pool.
> If I create and release the autorelease pool inside "while loop"
> then it may affect
> the performance of application.
"may" affect? Have you measured it and found it to be an issue?
Consider releasing the pool every 10th or 100th time depending on
memory foot print you want to control.
-Shawn
_______________________________________________
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