Freeing an class instance from memory in the c code

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
amar123deep
Posts: 12
Joined: Tue Sep 27, 2016 2:29 pm

Freeing an class instance from memory in the c code

Post by amar123deep » Thu Jan 19, 2017 1:48 pm

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.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

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

Post by dhylands » Thu Jan 19, 2017 8:24 pm

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

Post Reply