Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: OO matlab - deleting objects
Replies: 6   Last Post: Feb 27, 2013 5:20 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
krindikzulmann@gmail.com

Posts: 8
Registered: 5/18/09
Re: OO matlab - deleting objects
Posted: May 19, 2009 7:02 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On May 19, 11:46 pm, "Steven Lord" <sl...@mathworks.com> wrote:
> <krindikzulm...@gmail.com> wrote in message
>
> news:bdda5d36-2ea2-4cc9-b8c3-efb23421e304@y34g2000prb.googlegroups.com...
>
>
>
>
>

> > On May 18, 6:43 pm, "Nasser Abbasi" <n...@12000.org> wrote:
> > > <krindikzulm...@gmail.com> wrote in message
>
> > >news:0beda853-2849-4199-9986-2543f502f482@d7g2000prl.googlegroups.com...
>
> > > > Do we have to do explicit memory cleanup in matlab
>
> > > No. See below
>
> > >http://www.mathworks.com/company/newsletters/digest/2008/sept/matlab-...
>
> > > "Object Life-Cycle Management
> > > MATLAB implements a strategy for object life-cycle management that
> > > supports
> > > destructors and destroys objects as soon as they become unreachable from
> > > any
> > > MATLAB workspace. The MATLAB language has always managed memory
> > > allocation
> > > by destroying workspace variables when a function exits, either through
> > > an
> > > error or through a normal return to the calling context. We wanted to
> > > preserve this simple model but also extend it to handle objects that
> > > might
> > > persist beyond the execution of a function (by being returned to a
> > > calling
> > > function or stored in some other object returned to a calling function).
> > > A MATLAB handle class can define a delete method that behaves very much
> > > like
> > > a destructor in languages like C++ (Figures 3a and 3b). In MATLAB, a
> > > delete
> > > method is called just before an object is destroyed because the object
> > > can
> > > no longer be accessed from any MATLAB variable. The delete method can be
> > > used to close a file, close an external application, or notify another
> > > object that needs to react to the destruction of the first object. It is
> > > defined by the handle class, and only handle classes have destructors in
> > > MATLAB. "

>
> > > "Some programmers might find it strange that non-handle objects have no
> > > destructors. Since MATLAB object destruction is always automated, a
> > > non-handle object that holds other objects does not need to do anything
> > > to
> > > destroy those other objects."

>
> > > --Nasser
>
> > Thanks. But I saw the above mentioned code from an experienced matlab
> > pro

>
> > Even mathworks says below
> > "a non-handle object that holds other objects does not need to do
> > anything to
> > destroy those other objects"

>
> > does this imply handle objects do have to clean objects inside them
> > explicitly?

>
> No.
>
> When a non-handle object is no longer accessible, it and all its properties
> are cleared from memory just like normal variables when they go out of scope
> (like when the function whose workspace they are in exits.)  If that
> non-handle object contains another object in one of its properties, then if
> that other object is a non-handle object it too will be cleared from memory;
> if it is a handle object, its delete method (if any) will be called, then it
> will be cleared from memory.  Thus in neither of those situations do you,
> the user, need to do anything special.
>
> When a handle object is no longer accessible, the same procedure as I
> described above happens, except that its delete method is called before it
> is cleared from memory.  The reason the text above calls out non-handle
> objects, I believe, is because they operate somewhat differently than users
> may expect based on their experience with other object-oriented languages
> (in that they don't have destructors.)
>
> --
> Steve Lord
> sl...@mathworks.com


thanks.

So i believe the bottom line is
when a handle is destroyed if it has handle members they too are
automatically deleted(delete() called if it exists)
may be good news for lazy c++ programmers :)




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.