On Jan 8, 2014 9:11 PM, "Keith Winston" <keithw...@gmail.com> wrote: > > > On Wed, Jan 8, 2014 at 3:30 PM, Oscar Benjamin <oscar.j.benja...@gmail.com> wrote: >> >> The garbage collector has nothing to do with the memory usage of immutable types like ints. There are deallocated instantly when the last reference you hold is cleared (in CPython). So if you run out of memory because of them then it is because you're keeping them alive in your own code. Running the garbage collector with gc.collect cannot help with that. > > > Well that's sort of interesting... so it's different for mutables? huh. Anyway, I think I got what I can reasonably hope to get from this question, thanks to you and everyone! >
It's not that it's different for mutables specifically. The primary deallocation method is by reference count. This fails if there are reference cycles so CPython has a cyclic garbage collector that deals with those. Reference cycles can only emerge because of mutable containers. A slight correction to what I wrote above is that if an immutable object such as an int is referenced by an mutable one that is itself in a reference cycle then it wouldn't be deallocated until the cyclic garbage collector runs. Oscar
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor