I have a large list containing large objects from a single class:
my_list = [ LargeClass() for i in xrange(10000)]
I need to copy a slice of the list into an auxiliary list, but then to conserve memory, I would like to replace that slice in the original list by a bunch on None's:
new_list = my_list[:1000]
my_list[:1000] = [None] * 1000
My hope was that this would reduce the memory used by 'my_list' so I don't carry around two copies of the same "data". However, this doesn't release any memory. Calling the garbage collector doesn't make any difference either.
Is there any way to accomplish this?
Edit: I should have mentioned that the second list will be passed as an argument to a child process (multiprocessing), so it will be copied. When that's done, I don't need the data in the original list, which is just wasting memory now.