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

Some dels are uneffective #126

Open
kuraga opened this issue Sep 15, 2024 · 2 comments
Open

Some dels are uneffective #126

kuraga opened this issue Sep 15, 2024 · 2 comments

Comments

@kuraga
Copy link

kuraga commented Sep 15, 2024

In the Notebook, you sometimes do del of either a local variable or a function's argument just before return.

IMHO it does nothing there. Both of them are garbage collected exactly there, unconditionally.

@PangLuo
Copy link

PangLuo commented Dec 4, 2024

I'm not an expert on python garbage collection. This is what I get from ChatGPT:

Is del query Necessary?
In most cases, explicit del statements are not required because Python’s garbage collector (GC) will eventually free the memory for variables that go out of scope. However:
When working with large models or tensors (like in deep learning), waiting for the GC can lead to inefficiencies and OOM errors.
Explicitly calling del gives you precise control over when memory is released, which is particularly important in long-running processes like model training.

@kuraga
Copy link
Author

kuraga commented Dec 4, 2024

Yes but local variables are collected at the return, aren't they?

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

2 participants