// ResourceCache.mc import Toybox.Lang; import Toybox.WatchUi; class ResourceCache { hidden var cache as Dictionary<Symbol, WeakReference> = {} as Dictionary<Symbol, WeakReference>; function initialize() { } function get(symbol as Symbol) as Resource { var cache = self.cache; var value; var weakReference = cache.get(symbol); if (weakReference != null && weakReference.stillAlive()) { value = weakReference.get() as Resource; } else { value = WatchUi.loadResource(symbol); cache.put(symbol, value.weak()); logMemory("CACHE: ", ", loaded " + symbol.toString()); } return value; } } const CACHE = new ResourceCache();
<strings> <string id="AppName">Foo</string> <string id="foo" translatable="false">FOO</string> </strings>
class MyApp extends Application.AppBase { function initialize() { AppBase.initialize(); CACHE.get(Rez.Strings.foo); } }
I get this error:
Error: Symbol Not Found Error Details: Could not find symbol 'stillAlive' Stack: - get() at ResourceCache.mc:14 0x100021b9 - initialize() at MyApp.mc:21 0x10003ba4
In the manifest minApiLevel: 1.3.0, so there should be WeakReference.stillAlive.
I tried it in the simulator (SDK 6.4.2) on fr965 and fenix6, in both devices I get the same error.