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

A few questions about Memory Management


  • Subject: A few questions about Memory Management
  • From: "Adrian R. Foltyn" <email@hidden>
  • Date: Sat, 12 Feb 2005 02:56:43 +0100

Hi there,

I have a couple of questions about Memory Management and hope that somebody finds time to help me out here.

----------------------------------------------------------------
If I dealloc a NSArray holding other objects that were previously alloced and inited the objects that were contained in the array are neither released nor dealloced?


----------------------------------------------------------------

If I understood correctly onelinecoding in Cocoa is bad if you care about how much memory your program uses. As an example:

NSString *dreamWorld = [[[NSString initWithContentsOfFile:@"/path/to/realWorld.txt"] componentsSeparatedByString:@"hate"] componentsJoinedByString:@"love"];

With the above line I will never have the chance to send a release message to the NSString instance that stores the contents of the file and the NSArray instance that stores the delimited text as I don't have any pointers in place that reference to them. Neither the end of the method this code is executed in nor the deallocation of the object this method is used in will result in removing the NSString and NSArray instance from memory.

So is there no other way of disposing of those objects than to say:

NSString *realWorld;
NSString *dreamWorld;
NSArray *delimitedRealWorld;

realWorld = [NSString initWithContentsOfFile:@"/path/to/realWorld.txt"];
delimitedRealWorld = [realWorld componentsSeparatedByString:@"hate"];
dreamWorld = [delimitedRealWorld componentsJoinedByString:@"love"];


[realWorld release];
[delimitedRealWord release];

----------------------------------------------------------------
In the documentation for NSArray there is this example code:
NSArray *pathArray = [NSArray arrayWithObjects:@"System", @"Library", nil];
NSLog("The path is /%@.\n", [pathArray componentsJoinedByString:@"/"]);


Is it impossible to dealloc the resulting NSString instance of the componentsJoinedByString: call?
Would it be safe to say that example code in the documentation is not a good place to study memory management as it tries to demonstrate a concept in brief?


----------------------------------------------------------------
If I would completely ignore memory management while writing a simple command line tool does the system free the objects in memory after the tool exits?


What happens to the memory if it crashes?

----------------------------------------------------------------

Thanks in advance,

Adrian

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: A few questions about Memory Management
      • From: Jeremy French <email@hidden>
    • Re: A few questions about Memory Management
      • From: James Spencer <email@hidden>
    • Re: A few questions about Memory Management
      • From: Charlton Wilbur <email@hidden>
    • Re: A few questions about Memory Management
      • From: Bob Ippolito <email@hidden>
  • Prev by Date: Re: Philosophy of FSRef - way
  • Next by Date: Re: A few questions about Memory Management
  • Previous by thread: Memory management question.
  • Next by thread: Re: A few questions about Memory Management
  • Index(es):
    • Date
    • Thread