• 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: Serge Meynard <email@hidden>
  • Date: Fri, 11 Mar 2005 14:00:03 -0500

Hi All,

I have some memory management questions relating two classes of object that point to eachother.

[snip]

And I realize I am leaking memory here. The -dealloc of IRViewSegment is never called.

Now I see multiple solutions, but they all seem hackish:
1. Don't have the IRSegment retain the IRViewSegment in -registerView:
2. Overwrite the -release of IRViewSegment and implement IRSegment's -detachView: there
3. Instead of [segmentViewsArray removeAllObjects] iterate through the Array and send all IRViewSegments another -release
4. Instead of [segmentViewsArray removeAllObjects] iterate through the Array and have IRViewSegments be -dealloc -ed
5. Instead of [segmentViewsArray removeAllObjects] iterate through the Array and send all IRViewSegments (viewSeg) [[viewSeg segmentObject] detachView: viewSeg];


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 ...

Any help?
Thanks,
dirk

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

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

  • Prev by Date: Re: Is Mac Mini capable to develop cocoa app?
  • Next by Date: Newbie: setting a delegate to NSWindow
  • Previous by thread: memory problem with bi-directional referenced objects
  • Next by thread: Re: memory problem with bi-directional referenced objects
  • Index(es):
    • Date
    • Thread