# Object type: examples with methods saveobj(), loadobj(), delete()

**URL:** <https://scilab.discourse.group/t/object-type-examples-with-methods-saveobj-loadobj-delete/1098>\
**Category:** General usage\
**Created:** [December 16, 2025, 10:35am UTC](https://scilab.discourse.group/t/object-type-examples-with-methods-saveobj-loadobj-delete/1098 "2025-12-16T10:35:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![davcheze](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@davcheze](https://scilab.discourse.group/u/davcheze)\
**Post date:** [December 16, 2025, 10:35am UTC](https://scilab.discourse.group/t/object-type-examples-with-methods-saveobj-loadobj-delete/1098/1 "2025-12-16T10:35:13Z")

</div>

Hello,

about object variables saving and loading, is there a few example how to implement `saveobj()`, `loadobj()` and `delete()` overloading function in `classdef`object ? Currently there’s neither example nor details in the documentation.

Especially, the sentence about `saveobj()` is a bit obscure:

- 

> You have to return a native scilab variable (struct, list, …) except objects that contains all data you want to save.

thank you

David

---

<div class="post-metadata">

**Author:** ![antoine.elias](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/antoine.elias/32/16_2.png) [@antoine.elias](https://scilab.discourse.group/u/antoine.elias)\
**Post date:** [December 16, 2025, 4:07pm UTC](https://scilab.discourse.group/t/object-type-examples-with-methods-saveobj-loadobj-delete/1098/2 "2025-12-16T16:07:01Z")

</div>

Hello David,

The idea is to save only the properties (since the methods are in the `classdef` definition).

Here is a concise example:

```scilab
classdef demosave
    properties
        a
        b
    end

    methods
        function demosave(a,b)
            this.a = a;
            this.b = b;
        end

        function st = saveobj()
            disp("save properties");
            st.a = this.a;
            st.b = this.b;
        end

        function loadobj(st)
            disp("reload properties")
            this.a = st.a;
            this.b = st.b;
        end

        function delete()
            disp("demosave destructor");
        end
    end
end

a = demosave(12, "test");
save("TMPDIR/save.sod", "a");
clear a; //call delete
load("TMPDIR/save.sod");
a

```

**BUT** , while writing this message, I noticed there’s a bug in `loadobj`: the data we receive (`st` in my example) doesn’t contain the struct but `this` instead.  
I reported the issue ([#17513](https://gitlab.com/scilab/scilab/-/issues/17513))

Best regards,  
Antoine

---

<div class="post-metadata">

**Author:** ![davcheze](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@davcheze](https://scilab.discourse.group/u/davcheze)\
**Post date:** [December 17, 2025, 4:26pm UTC](https://scilab.discourse.group/t/object-type-examples-with-methods-saveobj-loadobj-delete/1098/3 "2025-12-17T16:26:49Z")

</div>

Thank you Antoine, clear now !

Out of curiosity, is really needed the destructor since Scilab is not complaining when I perform a `clear` while there was an object variable in the memory stack ?

Maybe good to include in demo a case or a note about when it makes sense to perform special action when removing the object instance (link with a third party code for instance ?).

Thank you

David

---

<div class="post-metadata">

**Author:** ![antoine.elias](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/antoine.elias/32/16_2.png) [@antoine.elias](https://scilab.discourse.group/u/antoine.elias)\
**Post date:** [December 17, 2025, 6:03pm UTC](https://scilab.discourse.group/t/object-type-examples-with-methods-saveobj-loadobj-delete/1098/4 "2025-12-17T18:03:56Z")

</div>

Absolutely — use cases for a destructor will be very rare.  
It might be used to release a hardware resource or close a connection, that kind of thing.  
But as long as you only use standard Scilab variables, you’ll probably never need one.  
Matrices, structs, lists, … will be deleted automatically when the instance is destroyed.

---

<div class="post-metadata">

**Author:** ![antoine.elias](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/antoine.elias/32/16_2.png) [@antoine.elias](https://scilab.discourse.group/u/antoine.elias)\
**Post date:** [February 5, 2026, 10:51am UTC](https://scilab.discourse.group/t/object-type-examples-with-methods-saveobj-loadobj-delete/1098/5 "2026-02-05T10:51:49Z")

</div>

We have made a new release [2026.0.1](https://www.scilab.org/download/scilab-2026.0.1) that fixes the issue [#17513](https://gitlab.com/scilab/scilab/-/issues/17513)
