Function removes chained list

Asked

Viewed 168 times

1

Save everyone, I’m learning chained list in python, as I already have some knowledge of list in C hit me doubt about node removal, the basis of the algorithms I used in some exercises is this:

Algorithm remove_first(L):
    if L.head is None then
        Indicate an error: the list is empty.
    L.head = L.head.next 
    L.size = L.size−1 

I had a question about a memory leak. As the removal of nodes apparently works only with a pointer exchange, I was left with doubt whether the memory, with this exchange, is allocated and inaccessible or not, if the exchange already makes available the memory? I thought of the C function free, is there any analog method in python to make memory available? If the case.

1 answer

1


This question has already been answered in the English OS.

Python uses garbage collector for memory control. Thus, gc once wipes memory by releasing objects that are not referenced.

Therefore, using the command del vc can mark the object as "deleteable" and gc will, at some point, release the memory used by this object.

Source:

How can I explicitly free memory in Python?

Documentación Oficial

Browser other questions tagged

You are not signed in. Login or sign up in order to post.