Re: MutableArrays losing its contents?
Re: MutableArrays losing its contents?
- Subject: Re: MutableArrays losing its contents?
- From: "M. Uli Kusterer" <email@hidden>
- Date: Mon, 1 Dec 2003 11:29:18 +0100
At 2:08 Uhr -0500 01.12.2003, Lee Morgan wrote:
I have a NSMutableArray that keeps a list of NSURL. The problem I
have is that even though the array is in my class's header its
contents are not retained from the method that they are added from.
What I'm trying to say is that I have a open file method that gets
the url and adds it to the array then another method that is setup
to get the url from the array and open it.
The problem I'm having is that even if I retain the array and the
objects within it it doesn't exists when the second method tries to
access it. I know its getting added to the array because I can use
it from the array while it is in the first method (the one that gets
the URL and puts it into the array).
Several options how I would produce such weird behavior:
a) You're somewhere overwriting the pointer to your array with a new
one to an empty array. The best indicator for this is if [yourArray
count] is 0.
b) You're declaring the variable/outlet to hold the array, but you
forgot to initialize it. Often you get a crash, but sometimes you're
lucky. Also known to "straight C" programmers as `long* foo =
0xDEADBEEF;4
c) You've declared your instance variable in the wrong scope, or
you've declared a variable of the same name as your instance variable
that "hides" it. That way, you get a new copy of the variable each
time.
d) You're calling release or autorelease on your array element where
you shouldn't, thus undoing the "retain" the array itself did to
ensure things like this don't happen. A good indicator for this is
that [yourArray count] is still right, but the objects are all
garbage, or even cause access exceptions and bring down your program.
e) You got the order of calls wrong. openFile: on an NSDocument is
usually called *after* init, but *before* awakeFromNib. This comes in
handy for the cases where the file's contents decide what NIB you're
loading, but can be a real pain if you just wanted to update your
GUI. If any of your objects come from a NIB through an outlet, check
for this.
f) Your computer has gone nuts and you're not at fault. In that case,
the only thing that's helped me was to do a complete rewrite of the
entire project, or at least of the part that is misbehaving. ;-)
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.