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

Consider releasing returned values from instance fns #242

Open
cnuernber opened this issue Mar 31, 2023 · 0 comments
Open

Consider releasing returned values from instance fns #242

cnuernber opened this issue Mar 31, 2023 · 0 comments

Comments

@cnuernber
Copy link
Collaborator

This will collect memory automatically:

(py/run-simple-string "
import torch.utils.data as tud
import torch

class DebugDataset (tud.Dataset):
    def __init__(self):
        pass
    def __len__(self):
        return 1000
    def __getitem__ (self, i):
        return torch.rand(1000, 1000, 1000)

d = DebugDataset()
print(d[0])
print(d[0])")

If the user defines a dataset using clojure and this will cause issues unless the user spams (System/gc):

(let [globals! (py/module-dict (py/add-module "__main__"))]
  (.put globals! "DebugDatasetClj" DebugDataset))

(py/run-simple-string "
d = DebugDatasetClj()
print(d[0])
print(d[0])")

The issue is make-instance-fn runs in the normal jvm context so it is keeping jvm references to the produced items. It does not need to do this; the normal python reference keeping system will work just fine. Fixing this in a robust way will require some thought :-)

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

1 participant