Re: Simple memory problem

2009-02-06 Thread harry greenmonster
I cant help but think the preferable way Objective C should would is to send a release automatically to the receiver of a product of itself. inputString = [inputString myMethod]; Its fairly clear in this situation that the original 'inputString' is not wanted and needs to die, and would

Re: Simple memory problem

2009-02-06 Thread Jeremy Pereira
On 6 Feb 2009, at 06:32, Martin Wierschin wrote: On Feb 5, 2009, at 4:42 PM, Steve Sisak wrote: NSString * newString = [inputString stringByReplacingCharactersInRange:range withString:@]; [inputString release]; // release old inputString inputString = [newString retain];

Re: Simple memory problem

2009-02-06 Thread harry greenmonster
Yes, memory management is a weak point of mine, which I'm currently trying to resolve. Last time I had any use for in-depth memory management was 15 years ago. By posing these questions I'm hoping to clear up grey areas, and they should not be taken as serious proposals for addition to the

Re: Simple memory problem

2009-02-06 Thread harry greenmonster
Forgot to add: As long as the returned type was the same. So instead.. inputString = [inputString StringFromMyMethod]; On 6 Feb 2009, at 13:32, harry greenmonster wrote: Yes, memory management is a weak point of mine, which I'm currently trying to resolve. Last time I had any use for

Re: Simple memory problem

2009-02-06 Thread Steve Sisak
At 1:32 PM + 2/6/09, harry greenmonster wrote: But why can the compiler not replace the data at the memory location pointed to by the old 'inputString' without making a second pointer (with the same name). This would then pose no problems in the scenarios you put forward.? If you use an

Re: Simple memory problem

2009-02-06 Thread Scott Ribe
Its fairly clear in this situation that the original 'inputString' is not wanted and needs to die... No, it is not. There could be any number of other variables in your program holding pointers to the same object. You know there are not, but the compiler does not know that. -- Scott Ribe

Re: Simple memory problem

2009-02-06 Thread Sherm Pendley
On Feb 6, 2009, at 8:32 AM, harry greenmonster wrote: Yes, memory management is a weak point of mine, which I'm currently trying to resolve. Last time I had any use for in-depth memory management was 15 years ago. Then you're in luck! Non-GC memory management in Cocoa is a *far* simpler

Re: Simple memory problem

2009-02-06 Thread Bill Bumgarner
On Feb 6, 2009, at 5:32 AM, harry greenmonster wrote: However, from a usability point of view, my points are still valid. Code such as inputString = [inputString myMethod]; looks to me like inputString data is no longer wanted, which in my case it wasn't. It is impossible for the compiler

Re: Simple memory problem

2009-02-06 Thread harry greenmonster
On 6 Feb 2009, at 14:18, Steve Sisak wrote: If you use an Objective-C 2.0 property (rather than a variable) and specifying retain semantics, you'll get that behavior -- with a bit of overhead. Ah interesting, just the kind of result I was hoping to obtain from asking dumb questions. In

Re: Simple memory problem

2009-02-06 Thread Bryan Henry
It sounds to me like you want to use garbage collection, not manual memory management. Does C automatically free() memory when pointers get replaced? No, obviously not. Doing so would be silly, and its even more silly to want such behavior with Objective-C. This: inputString = [NSString

Re: Simple memory problem

2009-02-06 Thread Martin Wierschin
On 2009.02.06, at 8:47 AM, Frédéric Testuz wrote: Le 6 févr. 09 à 07:32, Martin Wierschin a écrit : On Feb 5, 2009, at 4:42 PM, Steve Sisak wrote: NSString * newString = [inputString stringByReplacingCharactersInRange:range withString:@]; [inputString release]; // release old

Re: Simple memory problem

2009-02-06 Thread Michael Ash
On Fri, Feb 6, 2009 at 8:22 PM, Martin Wierschin mar...@nisus.com wrote: The only requirement the method has is to return an object that is valid for the caller. Because self is obviously valid, it's a perfectly legitimate return value. The fact that the caller releases that string after making

Simple memory problem

2009-02-05 Thread harry greenmonster
while([inputString isMatchedByRegex:regexString]){ range = [inputString rangeOfRegex:regexString]; inputString = [inputString stringByReplacingCharactersInRange:range withString:@]; } 'inputString' is a 5mb text file, Activity Monitor shows that memory

Re: Simple memory problem

2009-02-05 Thread Graham Cox
On 6 Feb 2009, at 10:39 am, harry greenmonster wrote: a pointer address when replaced by another address free's up the old memory location it once pointed to, no? No. It just means you orphaned the object - the memory it occupies is still err, occupied. However, in this case it's OK to

Re: Simple memory problem

2009-02-05 Thread Nick Zitzmann
On Feb 5, 2009, at 4:39 PM, harry greenmonster wrote: 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

Re: Simple memory problem

2009-02-05 Thread Ken Thomases
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'

Re: Simple memory problem

2009-02-05 Thread Shawn Erickson
On Thu, Feb 5, 2009 at 3:39 PM, harry greenmonster southwestmons...@googlemail.com wrote: 'inputString' is a 5mb text file, Since inputString is large you really should avoid causing it to be copied over and over again which -[NSString stringByReplacingCharactersInRange:withString:] is doing.

Re: Simple memory problem

2009-02-05 Thread harry greenmonster
I had already tried an NSAutoreleasePool but came across issues, it released inputString so as useless for the next iteration. So I tried keeping it around with... if (inputString != nil) { [inputString retain]; /* Keep match around.

Re: Simple memory problem

2009-02-05 Thread harry greenmonster
NSMutableString, good idea, I think that will work, will try that thanks. And thanks everyone else. On 6 Feb 2009, at 00:16, Shawn Erickson wrote: On Thu, Feb 5, 2009 at 3:39 PM, harry greenmonster southwestmons...@googlemail.com wrote: 'inputString' is a 5mb text file, Since

Re: Simple memory problem

2009-02-05 Thread Shawn Erickson
On Thu, Feb 5, 2009 at 4:16 PM, Shawn Erickson shaw...@gmail.com wrote: On Thu, Feb 5, 2009 at 3:39 PM, harry greenmonster southwestmons...@googlemail.com wrote: 'inputString' is a 5mb text file, Since inputString is large you really should avoid causing it to be copied over and over again

Re: Simple memory problem

2009-02-05 Thread Graham Cox
On 6 Feb 2009, at 11:16 am, Shawn Erickson wrote: Since inputString is large you really should avoid causing it to be copied over and over again I agree wholeheartedly, the autorelease pool solution is a sticking plaster on a gaping wound. A better approach is to avoid the need for it

Re: Simple memory problem

2009-02-05 Thread Scott Ribe
So, how do I keep a copy hanging around AND kill the mysterious new copy then (which shares the same name as the old one presumably)? 2 pointer variables... -- Scott Ribe scott_r...@killerbytes.com http://www.killerbytes.com/ (303) 722-0567 voice

Re: Simple memory problem

2009-02-05 Thread Steve Sisak
At 12:17 AM + 2/6/09, harry greenmonster wrote: So, how do I keep a copy hanging around AND kill the mysterious new copy then (which shares the same name as the old one presumably)? Retain the copy you want to keep around manually: while([inputString isMatchedByRegex:regexString]) {

Re: Simple memory problem

2009-02-05 Thread Martin Wierschin
On Feb 5, 2009, at 4:42 PM, Steve Sisak wrote: NSString * newString = [inputString stringByReplacingCharactersInRange:range withString:@]; [inputString release]; // release old inputString inputString = [newString retain]; // retain new inputString This sequence is not