I am working on a custom text field for a touch device and this text field is to be used in games. This custom text field is a class and has a variable in which the keypad image is stored which is static variable, if I have to display 2 text field in one page(screen) I’ll have to create 2 objects of the text field class and since the keypad image is stored in a static variable it would be shared by both the objects, now I want to know, if any objects are created of the custom keypad class, are these objects(memory) being referenced by any variable, if not I want to free the image memory and reload it when a new object is created.
Share
If you have access to
WeakReference, you could keep a staticWeakReferenceto the image in your class, and have a non-static (strong) reference in instances of your class:That makes the keypad image eligible to garbage collection as soon as there are no instances referencing it, otherwise it’s kept around and shared between instances.