SEP: add a `%foo_clear` overloading

Abstract

Some Scilab features are implemented through a mlist object and using the overloading mechanism to call a generic gateway on an operation. This is the case for the external_object (and JIMS), xml and hdf5 functionalities. To correctly call a destructor (to release resources, free mapping tables, etc...) a specific gateway is implemented and should be called to avoid memory leaks. This SEP propose to add an overloading %foo_clear called on foo mlist destruction to avoid the specific gateway thus let the mlist behave as other Scilab values.

Requirements

A %foo_clear function should be called on foo mlist destruction by the interpreter. If not defined, no error is produced and nothing is performed instead. This function will take an argument representing the deleted mlist value;

Atop of this deletion management, Scilab functionalities could be improved to handle this new behavior. For example, jremove (from external_object_java), xmlDelete (from xml) and h5close (from hdf5) could be called on deletion to avoid resource leaks and let the user clear the associated mlist.

The following bugs have been entered on Bugzilla to track similar or related problems/wishlist:

Mailing list threads

http://mailinglists.scilab.org/SEP-add-a-foo-delete-overloading-td4038898.html

Other software

Examples

Explicit call

   1 function %foo_clear(o)
   2         disp("resource deleted")
   3 endfunction
   4 
   5 value = mlist("foo");
   6 clear value

Implicit call

   1 function %foo_clear(o)
   2     disp("clear foo");
   3 endfunction
   4 
   5 function do_someting()
   6     value = mlist("foo");
   7 endfunction
   8 
   9 do_someting(); // %foo_clear will be call at the end of do_something

   1 function %foo_clear(o)
   2     disp("clear foo");
   3 endfunction
   4 
   5 function value = do_someting_and_return()
   6     value = mlist("foo");
   7 endfunction
   8 
   9 x = do_someting_and_return();
  10 x = 1; //call %foo_clear overload before replace


CategorySep

public: SEP add a %foo_delete overloading (last edited 2019-01-03 17:26:47 by clement.david@scilab-enterprises.com)