• 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: John MacMullin <email@hidden>
  • Date: Sun, 27 Jul 2003 14:37:12 -0700

I have been reading in Cocoa in a Nutshell, at page 9 and 14, the use
of memory management using the following pattern:

interface {
id title;
}

- (id)title {
return title;
}

- (void)setTitle:(id)aTitle {
[title autorelease];
title = [aTitle retain];
}

I have also seen the following method from Objective-C services:


interface {

NSMutableArray *companyRecords;

}


- (NSMutableArray *)companyRecords
{
return companyRecords;
}
- (void)setCompanyRecords:(NSMutableArray *)newCompanyRecords
{
[newCompanyRecords retain];
[companyRecords release];
companyRecords = newCompanyRecords;
}

An finally a third method:

interface {

NSMutableArray *companyRecords;

}

- (NSMutableArray *)companyArray
{
if (!companyRecords) {
companyRecords = [[[NSMutableArray alloc] init] retain];
}
return companyRecords;
}


Question: Is there a preferred method? And does one method cause
problems is used? The release in the last method is set in the dealloc.

John
_______________________________________________
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: Memory Management
      • From: John Randolph <email@hidden>
    • Re: Memory Management
      • From: Ben Dougall <email@hidden>
    • Re: Memory Management
      • From: Martin Häcker <email@hidden>
    • Re: Memory Management
      • From: "seaside.ki" <email@hidden>
  • Prev by Date: Re: FoundationKit md5/checksum
  • Next by Date: Public, private and protected variables
  • Previous by thread: Scrolling a WebView
  • Next by thread: Re: Memory Management
  • Index(es):
    • Date
    • Thread