• 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: How to add an array to a dictionary.....
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to add an array to a dictionary.....


  • Subject: Re: How to add an array to a dictionary.....
  • From: Ondra Cada <email@hidden>
  • Date: Sun, 13 Oct 2002 10:35:03 +0200

On Sunday, October 13, 2002, at 04:21 , Keith Pritchard wrote:

I'm trying to dynamically create an NSMutable array of NSMutable
dictionaries with which to populate an outline view.
...
Question is how to do this properly without memory leaking?

The topmost array needs to be retained. All the other pieces do not (since they are retained by the containers which hold them).

My problem at the moment is that I think I'm really making a massive
mess of memory management (I'm either creating one instance of the
children array rather than one per dictionary, or I'm creating lots but
managing to crash every time).

To be frank, I don't understand this one.

The code below, a result of frustration, manages to crash my app when I
try and populate it and since mail has crashed 4 times whilst writing
this email, I suspect I'm doing really horrible things to the system :)

I fear rather those who wrote Mail did. In my NeXTStep/OpenStep Mail just worked and never ever crashed; the new thing catches me in suprise so much often. Its latest trick is that it -- despite being offline -- tries DNS each few minutes, with my router being offline as well effectively locking for a minute or so. S***. Also it has stopped marking read messages properly for no apparent reason -- I guess 2000+ messages in a mailbox is just more than it can handle gracefully. Besides, it's slow like hell -- NeXTMail used to be ten times faster on its *much* slower hardware... The app's piece of cr** all right :((((

helppp? Thanks!

Back to business:

NSMutableArray *thread;
thread=[[NSMutableArray alloc] initWithCapacity:0];

NSMutableArray *thread=[[NSMutableArray alloc] init]; // or [[NSMutableArray array] retain]

[thread addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
somonesName,@"name",
(NSMutableArray *)nextArticle=[[NSMutableArray
alloc]init],@"children",nil] ];

NSMutableArray *ma;

[thread addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:
theName,@"name",
ma=[NSMutableArray array],@"children",
nil]];

[ma addObject:...];

The very same way you can add any number of nested structures. When "thread" gets released, the whole thing would get released (unless parts were retained by other code, of course).
---
Ondra Cada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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:
    • OT: Mail.app
      • From: Andreas Mayer <email@hidden>
    • Re: How to add an array to a dictionary.....
      • From: Keith Pritchard <email@hidden>
References: 
 >How to add an array to a dictionary..... (From: Keith Pritchard <email@hidden>)

  • Prev by Date: Ann: GeometryKit 0.7.5
  • Next by Date: Re: Displaying different languages in an NSTableView
  • Previous by thread: Re: How to add an array to a dictionary.....
  • Next by thread: Re: How to add an array to a dictionary.....
  • Index(es):
    • Date
    • Thread