• 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: Cocoa - Naive questions about memory
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa - Naive questions about memory


  • Subject: Re: Cocoa - Naive questions about memory
  • From: j o a r <email@hidden>
  • Date: Tue, 6 May 2003 13:04:59 +0200

Do you look at the warnings that the compiler give you?

1)

This is just plain wrong:

localArray = [[NSArray init] alloc];

If anything, it should have been:

localArray = [[NSArray alloc] init];

...but what you'd like to do with an empty immutable array is lost on me.

2)

Imediately after creating (?) the localArray you replace it with an autoreleased array returned from the "selectedCells" method. The first array you created is now lost forever = leaked. The array you replaced it with is already released, and hence you will crash if you release it again.

Just do this:

{
NSEnumerator *enumerator = [[myMatrix selectedCells] objectEnumerator];
id obj;
while ((obj = [enumerator nextObject]))
{
// stuff
}
}

j o a r


On Tuesday, May 6, 2003, at 12:44 Europe/Stockholm, Jacques wrote:

It's simple but sometime, I have some trouble.

Imagine this kind of code :

{
NSArray *localArray;

localArray = [[NSArray init] alloc];

localArray = [myMatrix selectedCells];

NSEnumerator *enumerator = [localArray objectEnumerator];
id object;

while(object = [enumerator nextObject])
{
.../...
}

// I don't need localArray now
[localArray release];
}

With the [localArray release] line my programm crash with a SIGBUS
error. If i comment this line, my programm work but it seems that there
is a release missing... No ?

What do you thing about that ?
_______________________________________________
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.

  • Follow-Ups:
    • Re: Cocoa - Naive questions about memory
      • From: Karl Goiser <email@hidden>
  • Prev by Date: Re: Return value on terminate
  • Next by Date: Re: clicking in NSMatrix.
  • Previous by thread: Re: Cocoa - Naive questions about memory
  • Next by thread: Re: Cocoa - Naive questions about memory
  • Index(es):
    • Date
    • Thread