• 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
Memory Management
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Memory Management


  • Subject: Memory Management
  • From: stuartbryson <email@hidden>
  • Date: Mon, 6 Aug 2001 23:45:47 +1000

Hi all,

I am currently learning about Mem management in Cocoa. I currently have a class called world with a NSArray *myArray declared in the interface file. The object has 2 main methods; Build and Render. I need to alloc the array within the Build method (as this is where the array is populated), and then use the array in Render and release it. I am not sure if there is a better way to achieve this?
Perhaps I can write my own init method for my world class where it declares the array and a "destructor" (C++ I know) method where I can release the array. That way the array would not need to be handled in Build or Render, just used. Does this make sense?
Also when the array is released, do the objects within the array automatically get released... see the code below:

- (void)Build
{
int i;
// Declare and create a temp 3D object and Ray
ThreeDObject *tempObj;
Ray *tempRay;
tempObj = [[Sphere alloc] init];
tempRay = [[Ray alloc] init];

// Init the 3D object array where all world objects are stored
threeDObjects = [[NSArray alloc] init];

// Add temp object
if ([self addThreeDObject:tempObj] == 0)
NSLog(@"Object could not be inserted");

// Add another temp object
if ([self addThreeDObject:tempObj] == 0)
NSLog(@"Object could not be inserted");

// Check to see intersects
for (i=0; i<[threeDObjects count]; i++)
if ([[threeDObjects objectAtIndex:i] intersects:tempRay])
NSLog(@"Ray intersected with Object");

[tempObj release];
[tempRay release];
}


Thanks all for your help.

Stuart


  • Follow-Ups:
    • Re: Memory Management
      • From: "Mike Vannorsdel" <email@hidden>
  • Prev by Date: Bug in NSFormatter (again)?
  • Next by Date: Re: Help, in Framework Hell!
  • Previous by thread: Re: Bug in NSFormatter (again)?
  • Next by thread: Re: Memory Management
  • Index(es):
    • Date
    • Thread