Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Good old times has an incorrect line #30

Open
milesmajefski opened this issue Nov 22, 2016 · 3 comments
Open

Good old times has an incorrect line #30

milesmajefski opened this issue Nov 22, 2016 · 3 comments

Comments

@milesmajefski
Copy link

del data[:]

As far as I know, this line would not have the desired effect of clearing the data memory. The slice notation Python makes a copy of the data. So that's not what we want. To fit in with the rest of the code and allow old data to be garbage collected, just assign an empty list to the data variable.

@witte-de-with
Copy link
Contributor

@milesmajefski are you quite sure? http://stackoverflow.com/a/1400622

@crista
Copy link
Owner

crista commented Dec 9, 2018

I think this is how you delete the contents of a list, but if you point me to documentation otherwise, I'll rewrite. Thanks.

@davidfstr
Copy link
Contributor

del data[:] is correct for deleting the contents of a list while leaving the list object itself alone.

By demonstration:

>>> data = [1,2,3]
>>> id(data)
4549185608
>>> del data[:]
>>> data
[]
>>> id(data)
4549185608
>>>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants