-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
Description
Right now, the @memoize macro creates the cache dictionary using eval:
Lines 49 to 52 in 1709785
| fcachename = Symbol("##", f, "_memoized_cache") | |
| fcache = isdefined(Main, fcachename) ? | |
| getfield(Main, fcachename) : | |
| Core.eval(Main, :(const $fcachename = ($dicttype)())) |
This is generally considered a bad idea in macros, and until recently, also caused an error here because the code was
evaling into the Memoize package (see #32).
Right now, using eval gives the following behavior:
- all memoized methods of a given function share the memoization cache
- if a method is overwritten, the cache is cleared, and any other global resources created/held by the previous version of that method are released:
Lines 257 to 266 in 1709785
finalized = false @memoize function method_rewrite() x = [] finalizer(x->(global finalized; finalized = true),x) x end method_rewrite() @memoize function method_rewrite() end GC.gc() @test finalized
I made one attempt to simply use a different cache dictionary for each method of a given function (JuliaCollections:1709785...JuliaCollections:a9170e5). This mostly works, but as-is causes the test above to fail, because the old cache is not released when the method is overwritten.
There may be an easy way around this, but it's not obvious to me right now.
Thoughts and/or pull requests welcome!
Cc: @cstjean