• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Simple memory problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple memory problem


  • Subject: Re: Simple memory problem
  • From: Ken Thomases <email@hidden>
  • Date: Thu, 5 Feb 2009 17:56:17 -0600

On Feb 5, 2009, at 5:39 PM, harry greenmonster wrote:

while([inputString isMatchedByRegex:regexString]){

	range = [inputString rangeOfRegex:regexString];

inputString = [inputString stringByReplacingCharactersInRange:range withString:@""];

	}



'inputString' is a 5mb text file, Activity Monitor shows that memory increases by about 9mb per iteration. Which quickly becomes a serious problem.

I'm a little confused as to why I have a problem. My understanding is that 'inputString' (on the third line) is replaced by the modified version of itself. I was expecting the memory footprint for the app to reduce in size (if anything). Obviously I have the concept fundamentally wrong in my head.

a pointer address when replaced by another address free's up the old memory location it once pointed to, no?

No. The pointer merely stops pointing to what it used to.

If you are using garbage collection, then assigning the pointer _may_ make the object available for collection. I say "may" because the existence of another pointer pointing to the same object may keep the object around.

The thing is, the collector doesn't immediately collect everything which is collectable. You can give it hints that it should collect at certain points in your program.

If you're not using garbage collection, then the objects being created in your loop are likely to be accumulating in the autorelease pool. You should create a local autorelease pool within your loop, draining it at the end of each iteration.

Regards,
Ken

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Simple memory problem (From: harry greenmonster <email@hidden>)

  • Prev by Date: Re: Needed : set class for Cocoa
  • Next by Date: Re: Needed : set class for Cocoa
  • Previous by thread: Re: Simple memory problem
  • Next by thread: Re: Simple memory problem
  • Index(es):
    • Date
    • Thread