octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #46497] delete class destructor is not called


From: anonymous
Subject: [Octave-bug-tracker] [bug #46497] delete class destructor is not called when clearing handle class
Date: Sun, 22 Nov 2015 21:01:56 +0000
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:42.0) Gecko/20100101 Firefox/42.0

URL:
  <http://savannah.gnu.org/bugs/?46497>

                 Summary: delete class destructor is not called when clearing
handle class
                 Project: GNU Octave
            Submitted by: None
            Submitted on: Sun 22 Nov 2015 09:01:54 PM UTC
                Category: Interpreter
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Matlab Compatibility
                  Status: None
             Assigned to: None
         Originator Name: Marco Merlin
        Originator Email: address@hidden
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 4.0.0
        Operating System: Microsoft Windows

    _______________________________________________________

Details:

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




    _______________________________________________________

File Attachments:


-------------------------------------------------------
Date: Sun 22 Nov 2015 09:01:54 PM UTC  Name: myClass.m  Size: 131B   By: None

<http://savannah.gnu.org/bugs/download.php?file_id=35522>
-------------------------------------------------------
Date: Sun 22 Nov 2015 09:01:54 PM UTC  Name: myClass_cleanup.m  Size: 289B  
By: None

<http://savannah.gnu.org/bugs/download.php?file_id=35523>

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?46497>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]