Page 1 of 1

Freeing an class instance from memory in the c code

Posted: Thu Jan 19, 2017 1:48 pm
by amar123deep
Hi guys, I want to free a class instance from the memory in the c code. Can you please guide me how to do it? I have information about the QSTR of the instance. I had created the instance by calling mp_store_name function.

For a module, one can get information with mp_module_get(qstr_name_of_the_module), but have not seen similar function for a class instance.

Re: Freeing an class instance from memory in the c code

Posted: Thu Jan 19, 2017 8:24 pm
by dhylands
Generally speaking you don't need to. The garbage collector will free it when appropriate.

If you know that there is nothing pointing to the object and you really want to free it, you can use m_del or m_del_obj (prototypes in py/misc.h)

The only time I recall seeing this is when an object is allocated and something fails in the constructor and the object is no longer needed.
An example is here: https://github.com/micropython/micropyt ... ain.c#L504