bugGNU Octave - Bugs: bug #46497, classdef: delete destructor method...

 
 

bug #46497: classdef: delete destructor method is not called when clearing handle class

Submitter:  None
Submitted:  Sun 22 Nov 2015 09:01:54 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Marco Merlin Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 21 Feb 2019 10:58:03 PM UTC, comment #6: 

I think we can close this as Octave 5 is releasing soon. The delete method is called now. There are other open issues (e.g. bug #53844), we can file and work on related issues in other bug reports.

Mike Miller <mtmiller>
Group Member
Tue 22 May 2018 05:45:07 PM UTC, comment #5: 

I don't think this was reverted completely on the stable branch, the code that was added in b328ff3ce0f7 and 56201aad3462 is still present in the cdef_object_rep::release function. The delete method is still being called when an object is cleared.

Mike Miller <mtmiller>
Group Member
Tue 15 May 2018 08:06:10 PM UTC, comment #4: 

Due to a number of issues that were discovered after 4.4.0 was release, I had no other real choice than to undo this change.  A proper fix will have to wait until at least version 5.

http://hg.savannah.gnu.org/hgweb/octave/rev/61ba501d8f04

John W. Eaton <jwe>
Group administrator
Fri 27 Apr 2018 02:00:22 AM UTC, comment #3: 

Piotr: I pushed your change.  That uncovered a bug in the evaluator that I introduced with my big refactor last year.  Then I realized that Octave would crash if an exception was thrown in the delete method, so I fixed that with the same technique as is used in the octave_oncleanup destructor.  The final set of patches are:

http://hg.savannah.gnu.org/hgweb/octave/rev/4a46c83bcb71
http://hg.savannah.gnu.org/hgweb/octave/rev/b328ff3ce0f7
http://hg.savannah.gnu.org/hgweb/octave/rev/56201aad3462

maintainers: I know it's very late for this kind of thing, but I pushed on stable because having a working delete method makes handle classes substantially more useful and the bug in the evaluator was serious trouble waiting to happen.

John W. Eaton <jwe>
Group administrator
Thu 02 Nov 2017 06:14:33 PM UTC, comment #2: 

And I tested it as extensively as I could with no side effects.

The destructor is called only when clearing an object that inherits from handle and not when a classdef does not inherit from handle.

The way I arrived at this solution was to turn on DEBUG_TRACES in ov-classdef.cc and then I found the location where the handle_cdef_object destructor is called. That's where I added the cdef_class::delete_object() function which calls the classdef "delete()" method.

I also wrote a tests for the problem.

The patch filename is:
patch_classdef_destructor_bug46497.diff

(file #42322)

Piotr Held <jsoh425>
Sat 28 Nov 2015 11:33:27 AM UTC, comment #1: 

I can confirm the issue on Octave 4.0.0 and ubuntu.

Anonymous
Sun 22 Nov 2015 09:01:54 PM UTC, original submission:  

I have created a superclass inheriting from handle, an example here:


classdef myClass < handle
    methods
        function delete(obj)
        disp('delete was called');
        end
    end
end


Here is the Matlab behavior, sticking to my expectations, deleting the class when clearing the reference.


>> c = myClass

c =

  myClass with no properties.

>> clear c
delete was called
>>


On the contrary, Octave does not execute the delete method.


>> c = myClass
c =

<object myClass>

>> clear c
>>


Similarly, following suggestion from here
http://stackoverflow.com/questions/14057308/matlab-class-destructor-not-called-during-clear, I have tried to use the onCleanup event


classdef myClass_cleanup < handle
  properties
    cleanup;
  end

    methods
        function obj = myClass_cleanup()
          obj.cleanup = onCleanup(@()delete(obj));
        end

        function delete(obj)
        disp('delete was called');
        end
    end
end


Here is what Matlab does, even though it is not clear now what actually triggers the destructor.


>> c = myClass_cleanup
c =

<object myClass_cleanup>

>> clear c
>>


And here is Octave still happily avoiding the destructor.


>> c = myClass_cleanup
c =

<object myClass_cleanup>

>> clear c
>>


Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #35522:  myClass.m added by None (131B - text/x-objcsrc)
file #35523:  myClass_cleanup.m added by None (289B - text/x-objcsrc)

 

Carbon-Copy List
  • -email is unavailable- added by amro_octave
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by jsoh425 (Updated the item)
  • -email is unavailable- added by cbm
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 19 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-02-21 mtmiller Carbon-CopyRemoved mtmiller -
    2019-02-21 mtmiller Carbon-CopyRemoved 80942 -
    2019-02-21 mtmiller StatusPostponed Fixed
        Open/ClosedOpen Closed
    2018-10-10 amro_octave Carbon-Copy- Added amro_octave
    2018-10-08 mtmiller Dependencies- bugs #54800 is dependent
    2018-05-22 mtmiller Dependencies- bugs #53844 is dependent
    2018-05-22 mtmiller Dependencies- bugs #53956 is dependent
    2018-05-15 jwe StatusReady For Test Postponed
    2018-04-27 jwe StatusConfirmed Ready For Test
    2017-11-02 jsoh425 Attached File- Added patch_classdef_destructor_bug46497.diff, #42322
    2016-06-02 mtmiller StatusNone Confirmed
        Release4.0.0 dev
        Operating SystemMicrosoft Windows Any
        Summarydelete class destructor is not called when clearing handle class classdef: delete destructor method is not called when clearing handle class
    2016-05-26 cbm Carbon-Copy- Added cbm
        Carbon-Copy- Added mtmiller
    2015-11-22 None Attached File- Added myClass.m, #35522
        Attached File- Added myClass_cleanup.m, #35523

    Back to the top

    Powered by Savane 3.13-cf05.
    Corresponding source code