Memoization in Java Using Dynamic Proxy Classes
Subject:   Methods as Keys
Date:   2003-08-21 23:47:57
From:   anonymous2
Nice article. It's a very nice use of dynamic proxies to separate concerns. One thing you may wish to consider as part of your "fully featured version of Memoizer" is a WeakHashMap for your top-level map that maps Method instances to value caches. Using a "standard" map implementation will prevent the JVM from unloading any class that has a method as a key in your top-level map.

Alternatively, if you want to allow the JVM to unload classes but keep cached values for a method, you could use the fully-qualified "mangled" method names as the keys.

Of course, as long as you keep a reference to the dynamic proxy, you keep a reference to an instance of a class, which means the class wouldn't be a candidate for garbage collection anyway.

Just something to think about.

-- Chuck

1 to 1 of 1
1 to 1 of 1