comp-imaging / ProxImaL

A domain-specific language for image optimization.
MIT License
114 stars 29 forks source link

CompGraph class destructor not called #40

Open timmeinhardt opened 7 years ago

timmeinhardt commented 7 years ago

For my last project I had to perform an extensive hyperparameter optimisation during which I regularly ran out of memory. After spending some time to find the memory leak, I came across the CompGraph class which has a self reference cycle. Such a cycle prevents a class from being deleted.

The problem is the self injected into the other objects in those two lines:

self.forward_log = TimingsLog(self.nodes + [self])
self.adjoint_log = TimingsLog(self.nodes + [self])

To fix the problem I changed the code to [str(self)] which then only injects a string. Since there is generally only one computational graph, time logging stills works (exact object references should only be necessary for graph elements which appear more than once). But there is probably a more elegant way to resolve this issue.