• 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: memory problem with bi-directional referenced objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memory problem with bi-directional referenced objects


  • Subject: Re: memory problem with bi-directional referenced objects
  • From: Dirk van Oosterbosch <email@hidden>
  • Date: Fri, 11 Mar 2005 23:06:43 +0100


On 11-mrt-05, at 20:00, Serge Meynard wrote:
I have some memory management questions relating two classes of object that point to eachother.

[snip]

How would you implement such a system with bi-directional referencing? I have the feeling I am making it more complicated than it has to be, but right now I am leaking memory ...


Yes, you're making it more complicated than it is. Basically the rule is to never create loops in your memory code. Look for "Retain cycles" and "Weak References" in this page:


http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/ index.html

If you follow this rule in your design, things should become much simpler to manage. Always make it clear in your mind which object owns which.

Serge


Thanks Serge,
that makes things a lot clearer. Even gave me the insight that my formerly produced code was wrong to begin with.


However I have still a question about my design, because I might have a much bigger (meta) retain cycle at my hands:
I have four classes in a carré. Two controller classes and two view classes, or, two parent classes and two child classes.
IRController - IRView
| |
IRSegment -(?) IRViewSegment


the IRController has an IBOutlet to IRView and has a NSMutableArray of IRSegments
the IRView has an IBOutlet to IRController and has a NSMutableArray of IRViewSegments


Now I want to the IRSegment to know about which IRViewSegment is representing him and I want each IRViewSegment to know to which IRSegment they represent.
Should those both references be "weak"?



Thanks, dirk

_______________________________________________
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: memory problem with bi-directional referenced objects
      • From: Serge Meynard <email@hidden>
References: 
 >memory problem with bi-directional referenced objects (From: Dirk van Oosterbosch <email@hidden>)
 >Re: memory problem with bi-directional referenced objects (From: Serge Meynard <email@hidden>)

  • Prev by Date: Re: Is Mac Mini capable to develop cocoa app?
  • Next by Date: Re: Could not connect the action to target of class
  • Previous by thread: Re: memory problem with bi-directional referenced objects
  • Next by thread: Re: memory problem with bi-directional referenced objects
  • Index(es):
    • Date
    • Thread