Re: Why is [NSArray arrayWithObjects:] failing for me?
that’s fine, Aaron’s book is an excellent source. The issue is more that the memory management rules shouldn’t be paraphrased here. Too easy for people to make errors and confuse users. On Jan 4, 2010, at 11:24 AM, Alex Kac wrote: > Normally I’d agree, but people understand things in different ways. I found > reading Aaron Hillegass book on Cocoa far more understandable than Apple’s > docs. When I first started I used Apple’s docs as my reference and Aaron’s > book as a way to understand it. Now I just use the Apple docs, but for > beginners I strongly recommend that book. > > On Jan 4, 2010, at 6:11 AM, Roland King wrote: > >>> On 2010-01-03 00:08, Eric Smith wrote: Correct, do not release the array. If you don't create it with "init", or retain it, then you should not release it. >>> Eric, thank you for stating that rule. It should be easy enough to remember >>> and help me avoid this problem in the future. >> >> With respect to Eric, that's part of the rule, the rules are in the memory >> management guide and it's better to read them in full from the apple >> documentation than paraphrase them. > > Alex Kac - President and Founder > Web Information Solutions, Inc. > > "The optimist proclaims that we live in the best of all possible worlds; and > the pessimist fears this is true." > -- James Clabell > > > > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/scott%40cocoadoc.com > > This email sent to sc...@cocoadoc.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
Normally I’d agree, but people understand things in different ways. I found reading Aaron Hillegass book on Cocoa far more understandable than Apple’s docs. When I first started I used Apple’s docs as my reference and Aaron’s book as a way to understand it. Now I just use the Apple docs, but for beginners I strongly recommend that book. On Jan 4, 2010, at 6:11 AM, Roland King wrote: >> On 2010-01-03 00:08, Eric Smith wrote: >>> Correct, do not release the array. If you don't create it with "init", or >>> retain it, then you should not release it. >>> >> Eric, thank you for stating that rule. It should be easy enough to remember >> and help me avoid this problem in the future. > > With respect to Eric, that's part of the rule, the rules are in the memory > management guide and it's better to read them in full from the apple > documentation than paraphrase them. Alex Kac - President and Founder Web Information Solutions, Inc. "The optimist proclaims that we live in the best of all possible worlds; and the pessimist fears this is true." -- James Clabell ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
I don’t seem to have any issues with XCode at all beyond not being able to hover-inspect some vars (I just use po on the output window instead). On Jan 4, 2010, at 5:58 AM, Charles Jenkins wrote: > On 2010-01-03 00:08, Eric Smith wrote: >> Correct, do not release the array. If you don't create it with "init", or >> retain it, then you should not release it. >> > Eric, thank you for stating that rule. It should be easy enough to remember > and help me avoid this problem in the future. > > In my defense, there seems to be a bug in the latest XCode, which make > strings stored in NSArrays look like garbage when inspected during debugging. > So the elements of pnl appeared to be trashed immediately upon creation. > That's why I was looking for the bug in the wrong place. > > Does anyone else find XCode extremely buggy? I have to continually close and > reopen my editing window because the code display gets trashed and appears to > scramble my code. It doesn't really change the source code file; it just > makes it look as if I've randomly gone through the file deleting stuff, and > when I see that happen, I immediately save, close, and reopen the window, and > everything is fine. > > Mac software is usually first class, stable, and beautiful. How do folks > write such great software when they're stuck with such a sub-par IDE? :-) > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/alex%40webis.net > > This email sent to a...@webis.net Alex Kac - President and Founder Web Information Solutions, Inc. "I am not young enough to know everything." --Oscar Wilde ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
This has happened to me often. On Jan 4, 2010, at 8:24 AM, Dave Keck wrote: Does anyone else find XCode extremely buggy? I have to continually close and reopen my editing window because the code display gets trashed and appears to scramble my code. It doesn't really change the source code file; it just makes it look as if I've randomly gone through the file deleting stuff, and when I see that happen, I immediately save, close, and reopen the window, and everything is fine. This bug occurs for me fairly often - it usually happens when doing something using auto-completion. Luckily, as you said, it doesn't actually corrupt the file. :) ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/intrntmn%40aol.com This email sent to intrn...@aol.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
Here's another useful link: http://www.cocoadev.com/index.pl?NSZombieEnabled I find enabling 'zombies' to be an excellent way of detecting an 'over-released' object without getting horrible / delayed / cryptic crashes. I aways have them enabled during debugging. Just a note of caution though: nothing is ever freed with this option enabled (which, when you're only debugging, is not really important). And here is the 'tao of debugging' for OS X, which has a useful section on memory-related matters: http://developer.apple.com/mac/library/technotes/tn2004/tn2124.html Paul Sanders. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
On Jan 4, 2010, at 7:58 AM, Charles Jenkins wrote: On 2010-01-03 00:08, Eric Smith wrote: Correct, do not release the array. If you don't create it with "init", or retain it, then you should not release it. Eric, thank you for stating that rule. It should be easy enough to remember and help me avoid this problem in the future. That rule isn't complete. Just read the published memory management docs that someone else linked for you--several times. In my defense, there seems to be a bug in the latest XCode, which make strings stored in NSArrays look like garbage when inspected during debugging. So the elements of pnl appeared to be trashed immediately upon creation. That's why I was looking for the bug in the wrong place. Does anyone else find XCode extremely buggy? I have to continually close and reopen my editing window because the code display gets trashed and appears to scramble my code. It doesn't really change the source code file; it just makes it look as if I've randomly gone through the file deleting stuff, and when I see that happen, I immediately save, close, and reopen the window, and everything is fine. Mac software is usually first class, stable, and beautiful. How do folks write such great software when they're stuck with such a sub- par IDE? :-) I don't find it buggy. I find it first class, stable and beautiful. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
> Does anyone else find XCode extremely buggy? I have to continually close and > reopen my editing window because the code display gets trashed and appears > to scramble my code. It doesn't really change the source code file; it just > makes it look as if I've randomly gone through the file deleting stuff, and > when I see that happen, I immediately save, close, and reopen the window, > and everything is fine. This bug occurs for me fairly often - it usually happens when doing something using auto-completion. Luckily, as you said, it doesn't actually corrupt the file. :) ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
On 4.1.2010, at 13:58, Charles Jenkins wrote: > On 2010-01-03 00:08, Eric Smith wrote: >> Correct, do not release the array. If you don't create it with "init", or >> retain it, then you should not release it. >> > Eric, thank you for stating that rule. It should be easy enough to remember > and help me avoid this problem in the future. > > In my defense, there seems to be a bug in the latest XCode, which make > strings stored in NSArrays look like garbage when inspected during debugging. > So the elements of pnl appeared to be trashed immediately upon creation. > That's why I was looking for the bug in the wrong place. Yes, the data formatters in the debugger do not always work. Typing "po " (e.g. po [pnl objectAtIndex:0]) normally works. "po" stand for "print object". > > Does anyone else find XCode extremely buggy? Not at all. For me Xcode is extremely robust and a lot of fun to use. I use the latest version under Snow Leopard, but it was mostly the same under Leopard, too. My impression was that Xcode gained a lot of robustness when it was switched to GC. > I have to continually close and reopen my editing window because the code > display gets trashed and appears to scramble my code. It doesn't really > change the source code file; it just makes it look as if I've randomly gone > through the file deleting stuff, and when I see that happen, I immediately > save, close, and reopen the window, and everything is fine. Sounds scary, i’ve never seen this. > > Mac software is usually first class, stable, and beautiful. How do folks > write such great software when they're stuck with such a sub-par IDE? :-) They aren’t. There must be something very special with your setup. Best Kai ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
On 04-Jan-2010, at 8:58 PM, Charles Jenkins wrote: > On 2010-01-03 00:08, Eric Smith wrote: >> Correct, do not release the array. If you don't create it with "init", or >> retain it, then you should not release it. >> > Eric, thank you for stating that rule. It should be easy enough to remember > and help me avoid this problem in the future. With respect to Eric, that's part of the rule, the rules are in the memory management guide and it's better to read them in full from the apple documentation than paraphrase them. > > In my defense, there seems to be a bug in the latest XCode, which make > strings stored in NSArrays look like garbage when inspected during debugging. > So the elements of pnl appeared to be trashed immediately upon creation. > That's why I was looking for the bug in the wrong place. > > Does anyone else find XCode extremely buggy? I have to continually close and > reopen my editing window because the code display gets trashed and appears to > scramble my code. It doesn't really change the source code file; it just > makes it look as if I've randomly gone through the file deleting stuff, and > when I see that happen, I immediately save, close, and reopen the window, and > everything is fine. > > Mac software is usually first class, stable, and beautiful. How do folks > write such great software when they're stuck with such a sub-par IDE? :-) I've found XCode, especially the recent releases, to be very good indeed. Certainly the XCode released with Snow Leopard (and since updated) is stable and I've not had any of those issues with it myself. If you have repeatable issues with XCode there is an XCode users list with a lot of helpful people on it and a couple of the toolchain guys from Apple do read it from time to time and reply also. I've had several questions answered there (mostly about how to do X or Y, XCode has a bit of a learning curve especially when you start to get creative with targets and executables). > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org > > This email sent to r...@rols.org ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
On 04/01/2010, at 11:58 PM, Charles Jenkins wrote: > On 2010-01-03 00:08, Eric Smith wrote: >> Correct, do not release the array. If you don't create it with "init", or >> retain it, then you should not release it. >> > Eric, thank you for stating that rule. It should be easy enough to remember > and help me avoid this problem in the future. One of the rules of this forum is "don't restate the memory management rules", but instead point to the relevant documentation. While the gist of what Eric says is right, it's incomplete and potentially misleading, especially as 'init' does not create anything. > In my defense, there seems to be a bug in the latest XCode, which make > strings stored in NSArrays look like garbage when inspected during debugging. > So the elements of pnl appeared to be trashed immediately upon creation. > That's why I was looking for the bug in the wrong place. The debugger is gdb - Xcode merely acts as a window for it. I think I have seen the same effect but I don't think it's Xcode's fault necessarily. Ensure you are properly compiling for debug with no optimisation and so on. > Does anyone else find XCode extremely buggy? I have to continually close and > reopen my editing window because the code display gets trashed and appears to > scramble my code. It doesn't really change the source code file; it just > makes it look as if I've randomly gone through the file deleting stuff, and > when I see that happen, I immediately save, close, and reopen the window, and > everything is fine. > > Mac software is usually first class, stable, and beautiful. How do folks > write such great software when they're stuck with such a sub-par IDE? :-) I haven't experienced this. Some other minor irritations for sure, but nothing major. On the whole I've found Xcode to be pretty solid. It might be worth taking this up on the xcode users list, or at least having a look through its archives to see if it's a common problem. --Graham ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
On 4.1.2010, at 13:44, Charles Jenkins wrote: > Thank you to all who offered your expertise! > > Whatta dumb mistake! I thought all objects were retained once when created, > not auto-released. Gah! > > I've been programming for 20+ years--mostly with C++ and C#. Cocoa-ObjC has > the steepest learning curve of any programming I have ever done. Strange that you feel so. I’d say C++ is way more complex - although I did 20+ years of C++ coding and only 2 of ObjC/Cocoa. But in any case you can take the whole retain/release problem out of your learning curve by switching to GC - unless you are targeting the iPhone. > It makes me feel like an idiot, so you can certainly expect to see more of > these noobish questions from me... Thanks in advance for your help and > patience! Kai___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
On 2010-01-03 00:08, Eric Smith wrote: Correct, do not release the array. If you don't create it with "init", or retain it, then you should not release it. Eric, thank you for stating that rule. It should be easy enough to remember and help me avoid this problem in the future. In my defense, there seems to be a bug in the latest XCode, which make strings stored in NSArrays look like garbage when inspected during debugging. So the elements of pnl appeared to be trashed immediately upon creation. That's why I was looking for the bug in the wrong place. Does anyone else find XCode extremely buggy? I have to continually close and reopen my editing window because the code display gets trashed and appears to scramble my code. It doesn't really change the source code file; it just makes it look as if I've randomly gone through the file deleting stuff, and when I see that happen, I immediately save, close, and reopen the window, and everything is fine. Mac software is usually first class, stable, and beautiful. How do folks write such great software when they're stuck with such a sub-par IDE? :-) ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
Essential reading: http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html The 'memory management rules' are not complex. A much bigger problem is avoiding memory leaks. Paul Sanders. - Original Message - From: "Charles Jenkins" To: "Cocoa-Dev List" Sent: Monday, January 04, 2010 12:44 PM Subject: Re: Why is [NSArray arrayWithObjects:] failing for me? Thank you to all who offered your expertise! Whatta dumb mistake! I thought all objects were retained once when created, not auto-released. Gah! I've been programming for 20+ years--mostly with C++ and C#. Cocoa-ObjC has the steepest learning curve of any programming I have ever done. It makes me feel like an idiot, so you can certainly expect to see more of these noobish questions from me... Thanks in advance for your help and patience! ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
Thank you to all who offered your expertise! Whatta dumb mistake! I thought all objects were retained once when created, not auto-released. Gah! I've been programming for 20+ years--mostly with C++ and C#. Cocoa-ObjC has the steepest learning curve of any programming I have ever done. It makes me feel like an idiot, so you can certainly expect to see more of these noobish questions from me... Thanks in advance for your help and patience! ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
On Jan 3, 2010, at 2:30 PM, Seth Willits wrote: >> NSArray* pnl = [NSArray arrayWithObjects:pa,pb,pc,pd,nil]; >> [parentDocument setPlayerNameList:pnl]; >> [pnl release]; > > KABOOM. > > You are over-releasing pnl. The release call is unnecessary because the array > was not alloc/init'd, made by copy, or had retain called on it within this > method. And here I am responding to a resolved thread because my Mail window wasn't scrolled all the way to the top so I didn't see any replies. Oops. :) -- Seth Willits ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
On Jan 2, 2010, at 11:44 AM, Charles Jenkins wrote: > NSArray* pnl = [NSArray arrayWithObjects:pa,pb,pc,pd,nil]; > [parentDocument setPlayerNameList:pnl]; > [pnl release]; KABOOM. You are over-releasing pnl. The release call is unnecessary because the array was not alloc/init'd, made by copy, or had retain called on it within this method. -- Seth Willits ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
Message: 6 Date: Sat, 02 Jan 2010 14:44:21 -0500 From: Charles Jenkins Subject: Why is [NSArray arrayWithObjects:] failing for me? NSArray* pnl = [NSArray arrayWithObjects:pa,pb,pc,pd,nil]; [parentDocument setPlayerNameList:pnl]; [pnl release]; I think adding the strings to an array will retain them; that's why there aren't a bunch of retain calls here. setPlayerNameList should retain as well, so the only memory management I think I have to do here is release pnl once. The only memory management you have to do here is that you mustn't release pnl at all. And you've violated that one. m. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
On 03-Jan-2010, at 1:10 PM, Yandy Ramirez wrote: > the method [NSArray arrayWithObjects:] returns an autoreleased object, > there's no need for you to release it yourself. According to ObjC memory > management guidelines you only release when you. Retain and object, > init/alloc and object or copy it. In this case I think your array is getting > released before you have a chance to use it in your next method.. try this: > > NSString* pa = [playerA stringValue]; > NSString* pb = [playerB stringValue]; > NSString* pc = [playerC stringValue]; > NSString* pd = [playerD stringValue]; > NSArray* pnl = [NSArray arrayWithObjects:pa,pb,pc,pd,nil]; > * [pnl retain]; // or use a NSArray *pnl = [[NSArray alloc] > initWithObjects:] method.* > [parentDocument setPlayerNameList:pnl]; > [pnl release]; > > no need to retain it, just don't release it (ie remove the [ pnl release ] call). ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
the method [NSArray arrayWithObjects:] returns an autoreleased object, there's no need for you to release it yourself. According to ObjC memory management guidelines you only release when you. Retain and object, init/alloc and object or copy it. In this case I think your array is getting released before you have a chance to use it in your next method.. try this: NSString* pa = [playerA stringValue]; NSString* pb = [playerB stringValue]; NSString* pc = [playerC stringValue]; NSString* pd = [playerD stringValue]; NSArray* pnl = [NSArray arrayWithObjects:pa,pb,pc,pd,nil]; * [pnl retain]; // or use a NSArray *pnl = [[NSArray alloc] initWithObjects:] method.* [parentDocument setPlayerNameList:pnl]; [pnl release]; -- yandy On Sat, Jan 2, 2010 at 2:44 PM, Charles Jenkins wrote: > Hello, everyone. I'm struggling through the steep Cocoa learning curve, and > even things that should seemingly be very easy turn out to be difficult for > me. > > I have an NSView in which I ask for the player names for a 4-person game. I > have hooked the NSTextField objects to IBOutlet NSTextField* data members of > my view's class, and I am at the point where the user clicks 'OK' and I need > to save the player names. > > The NSTextField* variables are called playerA ... playerC, and i have no > problem with using [playerA stringValue] to get the name of a player. The > problem comes when I try to save the player name into an array. Here is the > current version of my code: > > NSString* pa = [playerA stringValue]; > NSString* pb = [playerB stringValue]; > NSString* pc = [playerC stringValue]; > NSString* pd = [playerD stringValue]; > NSArray* pnl = [NSArray arrayWithObjects:pa,pb,pc,pd,nil]; > [parentDocument setPlayerNameList:pnl]; > [pnl release]; > > I think adding the strings to an array will retain them; that's why there > aren't a bunch of retain calls here. setPlayerNameList should retain as > well, so the only memory management I think I have to do here is release pnl > once. > > pa, pb, pc, and pd are all good, according to the debugger as I step > through, so the call to arrayWithObjects: looks good. But when I get the > resulting array, all of the objects are trash and I get a BAD ACCESS > exception when anybody tries to use them. > > I'm using XCode 3.2.1 on Snow Leopard, but I'm building using the 10.5 or > later SDK, because I'm not using an 10.6-only features. > > So, what the heck am I doing wrong? Thanks! > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/yandyr%40gmail.com > > This email sent to yan...@gmail.com > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
you should go back and read the memory management documentation again until it's burned into your memory. arrayWithObjects returns an array you do not own and thus do not need to release (and must not). On 03-Jan-2010, at 3:44 AM, Charles Jenkins wrote: > Hello, everyone. I'm struggling through the steep Cocoa learning curve, and > even things that should seemingly be very easy turn out to be difficult for > me. > > I have an NSView in which I ask for the player names for a 4-person game. I > have hooked the NSTextField objects to IBOutlet NSTextField* data members of > my view's class, and I am at the point where the user clicks 'OK' and I need > to save the player names. > > The NSTextField* variables are called playerA ... playerC, and i have no > problem with using [playerA stringValue] to get the name of a player. The > problem comes when I try to save the player name into an array. Here is the > current version of my code: > > NSString* pa = [playerA stringValue]; > NSString* pb = [playerB stringValue]; > NSString* pc = [playerC stringValue]; > NSString* pd = [playerD stringValue]; > NSArray* pnl = [NSArray arrayWithObjects:pa,pb,pc,pd,nil]; > [parentDocument setPlayerNameList:pnl]; > [pnl release]; > > I think adding the strings to an array will retain them; that's why there > aren't a bunch of retain calls here. setPlayerNameList should retain as well, > so the only memory management I think I have to do here is release pnl once. > > pa, pb, pc, and pd are all good, according to the debugger as I step through, > so the call to arrayWithObjects: looks good. But when I get the resulting > array, all of the objects are trash and I get a BAD ACCESS exception when > anybody tries to use them. > > I'm using XCode 3.2.1 on Snow Leopard, but I'm building using the 10.5 or > later SDK, because I'm not using an 10.6-only features. > > So, what the heck am I doing wrong? Thanks! > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org > > This email sent to r...@rols.org ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
You should not be releasing pnl because you do not own a reference to it. The memory management rules explain why this is. -- David Duncan @ My iPhone On Jan 2, 2010, at 2:44 PM, Charles Jenkins wrote: Hello, everyone. I'm struggling through the steep Cocoa learning curve, and even things that should seemingly be very easy turn out to be difficult for me. I have an NSView in which I ask for the player names for a 4-person game. I have hooked the NSTextField objects to IBOutlet NSTextField* data members of my view's class, and I am at the point where the user clicks 'OK' and I need to save the player names. The NSTextField* variables are called playerA ... playerC, and i have no problem with using [playerA stringValue] to get the name of a player. The problem comes when I try to save the player name into an array. Here is the current version of my code: NSString* pa = [playerA stringValue]; NSString* pb = [playerB stringValue]; NSString* pc = [playerC stringValue]; NSString* pd = [playerD stringValue]; NSArray* pnl = [NSArray arrayWithObjects:pa,pb,pc,pd,nil]; [parentDocument setPlayerNameList:pnl]; [pnl release]; I think adding the strings to an array will retain them; that's why there aren't a bunch of retain calls here. setPlayerNameList should retain as well, so the only memory management I think I have to do here is release pnl once. pa, pb, pc, and pd are all good, according to the debugger as I step through, so the call to arrayWithObjects: looks good. But when I get the resulting array, all of the objects are trash and I get a BAD ACCESS exception when anybody tries to use them. I'm using XCode 3.2.1 on Snow Leopard, but I'm building using the 10.5 or later SDK, because I'm not using an 10.6-only features. So, what the heck am I doing wrong? Thanks! ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com This email sent to david.dun...@apple.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Why is [NSArray arrayWithObjects:] failing for me?
Just wondering if you need to release that array. On Sat, Jan 2, 2010 at 2:44 PM, Charles Jenkins wrote: > Hello, everyone. I'm struggling through the steep Cocoa learning curve, and > even things that should seemingly be very easy turn out to be difficult for > me. > > I have an NSView in which I ask for the player names for a 4-person game. I > have hooked the NSTextField objects to IBOutlet NSTextField* data members of > my view's class, and I am at the point where the user clicks 'OK' and I need > to save the player names. > > The NSTextField* variables are called playerA ... playerC, and i have no > problem with using [playerA stringValue] to get the name of a player. The > problem comes when I try to save the player name into an array. Here is the > current version of my code: > > NSString* pa = [playerA stringValue]; > NSString* pb = [playerB stringValue]; > NSString* pc = [playerC stringValue]; > NSString* pd = [playerD stringValue]; > NSArray* pnl = [NSArray arrayWithObjects:pa,pb,pc,pd,nil]; > [parentDocument setPlayerNameList:pnl]; > [pnl release]; > > I think adding the strings to an array will retain them; that's why there > aren't a bunch of retain calls here. setPlayerNameList should retain as > well, so the only memory management I think I have to do here is release pnl > once. > > pa, pb, pc, and pd are all good, according to the debugger as I step > through, so the call to arrayWithObjects: looks good. But when I get the > resulting array, all of the objects are trash and I get a BAD ACCESS > exception when anybody tries to use them. > > I'm using XCode 3.2.1 on Snow Leopard, but I'm building using the 10.5 or > later SDK, because I'm not using an 10.6-only features. > > So, what the heck am I doing wrong? Thanks! > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > 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: > http://lists.apple.com/mailman/options/cocoa-dev/edolecki%40gmail.com > > This email sent to edole...@gmail.com > -- http://ericd.net Interactive design and development ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Why is [NSArray arrayWithObjects:] failing for me?
Hello, everyone. I'm struggling through the steep Cocoa learning curve, and even things that should seemingly be very easy turn out to be difficult for me. I have an NSView in which I ask for the player names for a 4-person game. I have hooked the NSTextField objects to IBOutlet NSTextField* data members of my view's class, and I am at the point where the user clicks 'OK' and I need to save the player names. The NSTextField* variables are called playerA ... playerC, and i have no problem with using [playerA stringValue] to get the name of a player. The problem comes when I try to save the player name into an array. Here is the current version of my code: NSString* pa = [playerA stringValue]; NSString* pb = [playerB stringValue]; NSString* pc = [playerC stringValue]; NSString* pd = [playerD stringValue]; NSArray* pnl = [NSArray arrayWithObjects:pa,pb,pc,pd,nil]; [parentDocument setPlayerNameList:pnl]; [pnl release]; I think adding the strings to an array will retain them; that's why there aren't a bunch of retain calls here. setPlayerNameList should retain as well, so the only memory management I think I have to do here is release pnl once. pa, pb, pc, and pd are all good, according to the debugger as I step through, so the call to arrayWithObjects: looks good. But when I get the resulting array, all of the objects are trash and I get a BAD ACCESS exception when anybody tries to use them. I'm using XCode 3.2.1 on Snow Leopard, but I'm building using the 10.5 or later SDK, because I'm not using an 10.6-only features. So, what the heck am I doing wrong? Thanks! ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com