Re: Solving memory leaks

2010-03-28 Thread Michael Davey
OK, thanks for the links, and the help - I am going to read through and apply what I have learned to my code, I have already managed to fix two other leaks as a result of what I have learned. Thank you. On 28 Mar 2010, at 19:03, Philip Mobley wrote: > > On Mar 28, 2010, at 10:42 AM, mmalc Cr

Re: Solving memory leaks

2010-03-28 Thread Michael Davey
I cache the fields array on the first run so that the method is efficient - this is a generic SQLite db wrapper that may potentially be used to access 1000s of rows, and it seems perfectly reasonable that I should be able to store the fields in between SELECTs On 28 Mar 2010, at 19:04, Jack Ca

Re: Solving memory leaks

2010-03-28 Thread mmalc Crawford
On Mar 28, 2010, at 11:03 am, Philip Mobley wrote: > When calling setFields, you are then responsible for releasing the > "newFields" NSMutableArray you created in your sample code, because > [newFields mutableCopy] increments the ref counter. > This is not correct. [newFields mutableCopy] re

Re: Solving memory leaks

2010-03-28 Thread Philip Mobley
On Mar 28, 2010, at 10:42 AM, mmalc Crawford wrote: >> That would be gut for the fact that my fields are released and set to nil >> whenever a new SELECT query is executed - however, I think I can do this by >> emptying the array when a new query is done and just counting the size of >> the ar

Re: Solving memory leaks

2010-03-28 Thread Klaus Backert
On 28 Mar 2010, at 19:27, Michael Davey wrote: That would be gut for the fact that my fields are released and set to nil whenever a new SELECT query is executed - however, I think I can do this by emptying the array when a new query is done and just counting the size of the array in my fet

Re: Solving memory leaks

2010-03-28 Thread mmalc Crawford
On Mar 28, 2010, at 10:27 am, Michael Davey wrote: > That would be gut for the fact that my fields are released and set to nil > whenever a new SELECT query is executed - however, I think I can do this by > emptying the array when a new query is done and just counting the size of the > array i

Re: Solving memory leaks

2010-03-28 Thread Michael Davey
That would be gut for the fact that my fields are released and set to nil whenever a new SELECT query is executed - however, I think I can do this by emptying the array when a new query is done and just counting the size of the array in my fetch method - thanks... On 28 Mar 2010, at 18:11, Klau

Re: Solving memory leaks

2010-03-28 Thread Klaus Backert
On 28 Mar 2010, at 19:11, Klaus Backert wrote: MyOtherObject *myOtherObject = [fields objectWithKey: ...]; Correction: objectForKey Klaus ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comme

Re: Solving memory leaks

2010-03-28 Thread Klaus Backert
On 28 Mar 2010, at 18:40, Michael Davey wrote: 1. Some other piece of code assigns a new value to 'myFields' without releasing the old value. That is the only part of my code that adds values to the field. In order to handle your fields instance variable correctly, what do you think abou

Re: Solving memory leaks

2010-03-28 Thread Michael Davey
On 28 Mar 2010, at 02:14, Quincey Morris wrote: > On Mar 27, 2010, at 16:51, Noah Desch wrote: > >> If you are *not* using getters and setters but instead have myFields >> declared as: >> >> @interface MyClass >> { >> NSMutableDictionary *myFields; >> } >> >> and you use the above line o

Re: Solving memory leaks

2010-03-27 Thread Michael Davey
Thank you all so much for your responses - I will give them much better attention tomorrow, and sober :o) On 28 Mar 2010, at 02:23, Klaus Backert wrote: > > On 27 Mar 2010, at 23:16, Quincey Morris wrote: > >> On Mar 27, 2010, at 14:11, Klaus Backert wrote: >> >>> something like this (caution

Re: Solving memory leaks

2010-03-27 Thread Klaus Backert
On 27 Mar 2010, at 23:16, Quincey Morris wrote: On Mar 27, 2010, at 14:11, Klaus Backert wrote: something like this (caution: typed in mail, etc.) Yeah, something like this, but *not* this: self.myFields = [[NSMutableArray alloc] init]; That's a memory leak right there. :) Ye

Re: Solving memory leaks

2010-03-27 Thread Quincey Morris
On Mar 27, 2010, at 16:51, Noah Desch wrote: > If you are *not* using getters and setters but instead have myFields declared > as: > > @interface MyClass > { > NSMutableDictionary *myFields; > } > > and you use the above line of code, and subsequently release myFields in your > dealloc m

Re: Solving memory leaks

2010-03-27 Thread Keary Suska
On Mar 27, 2010, at 5:39 PM, Michael Davey wrote: > On 27 Mar 2010, at 22:16, Quincey Morris wrote: > >> On Mar 27, 2010, at 14:11, Klaus Backert wrote: >> >>> something like this (caution: typed in mail, etc.) >> >> >> Yeah, something like this, but *not* this: >> >>> self.myFields = [[N

Re: Solving memory leaks

2010-03-27 Thread Noah Desch
> but *not* this: > self.myFields = [[NSMutableArray alloc] init]; > > That's a memory leak right there. :) This discussion is confusing me a bit... lets see if I got this right: If you are *not* using getters and setters but instead have myFields declared as: @interface MyClass {

Re: Solving memory leaks

2010-03-27 Thread Michael Davey
On 27 Mar 2010, at 22:16, Quincey Morris wrote: > On Mar 27, 2010, at 14:11, Klaus Backert wrote: > >> something like this (caution: typed in mail, etc.) > > > Yeah, something like this, but *not* this: > >> self.myFields = [[NSMutableArray alloc] init]; > > That's a memory leak right t

Re: Solving memory leaks

2010-03-27 Thread Quincey Morris
On Mar 27, 2010, at 14:11, Klaus Backert wrote: > something like this (caution: typed in mail, etc.) Yeah, something like this, but *not* this: > self.myFields = [[NSMutableArray alloc] init]; That's a memory leak right there. :) Incidentally, I think the OP was mistakenly interpreting

Re: Solving memory leaks

2010-03-27 Thread Klaus Backert
On 27 Mar 2010, at 21:31, Michael Davey wrote: So, you are saying I should call a retain when I get my reference so that it is kept as an instance var? On 27 Mar 2010, at 19:33, Sandor Szatmari wrote: Every time this method runs you would loose the reference to the memory previously alloc

Re: Solving memory leaks

2010-03-27 Thread Michael Davey
So, you are saying I should call a retain when I get my reference so that it is kept as an instance var? On 27 Mar 2010, at 19:33, Sandor Szatmari wrote: > Every time this method runs you would loose the reference to the memory > previously allocated for the fields array. This happens when you