lecture18 - MemoryManagementTechniques Howcanweensureweclean

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 1 Memory Management Techniques How can we ensure we clean  up after ourselves?
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 2 You Have Two Choices Dynamically allocated objects  are “owned” by some other  object who is responsible for  deleting them Dynamically allocated  objects are responsible for  deleting themselves when  nobody is using them  anymore 
Background image of page 2
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 3 How have we been doing this? 1
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 4 Composition Makes Things Easy Document “owns” Actors When Document is destroyed,  it destroys any actors. CDocument::~CDocument() {      for(list<CActor *>::iterator  a=mActors.begin();                 a!=mActors.end(); a++)     {          delete *a;     }     mActors.clear(); }
Background image of page 4
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 5 Things are not always so simple, though directed graph   consists of nodes and  edges between the  nodes. In this case the  edges has  weights .
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 6 Ideas on the Memory Management? Suppose the graph is  deleted. How do we delete  all of the nodes and  edges? 2
Background image of page 6
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 7 One Approach DirectedGraph  simply owns all of  the nodes and  edges A common approach when you have a collection  of things that are all related. How would you  implement? Do you need the back links?
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CSE 335 Dr. Charles B. Owen Object-Oriented Programming 8 What about deleting nodes? What should happen  when I delete a node?
Background image of page 8
Object-Oriented Programming 9 What about deleting nodes? Can I just delete all from-edges 
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/12/2010 for the course CSE CSE 335 taught by Professor Owen during the Fall '10 term at Michigan State University.

Page1 / 27

lecture18 - MemoryManagementTechniques Howcanweensureweclean

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online