Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8694621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:49:38+00:00 2026-06-13T00:49:38+00:00

I am working on a custom text field for a touch device and this

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:49:39+00:00Added an answer on June 13, 2026 at 12:49 am

    If you have access to WeakReference, you could keep a static WeakReference to the image in your class, and have a non-static (strong) reference in instances of your class:

    public class CustomTextField {
        // Only necessary if multiple threads can create UI elements
        private static final Object lock = new Object();
        private static WeakReference<Image> keypadRef;
    
        private final Image keypad;
    
        public CustomTextField() {
            this.keypad = loadKeypad();
        }
    
        private static Image loadKeypad() {
            Image keypad = null;
            // Same comment as above: you don't need the lock if the UI elements are
            // not created in multiple threads.
            synchronized (lock) {
                if (keypadRef != null) {
                    keypad = keypadRef.get();
                }
                // Either there was no existing reference, or it referenced a GCed
                // object.
                if (keypad == null) {
                    keypad = new Image();
                    keypadRef = new WeakReference(keypad);
                }
            }
            return keypad;
        }
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working custom UserNamePasswordValidator that calls into my Oracle DB. This class
I am custom drawing text into a custom UITableViewCell, but am struggling in working
I have a nicely working custom CursorAdapter with customized ListView. This view allows the
i am working on a custom component in Delphi -7 for which i have
I am working on a custom Django form field and accompanying widget. While rendering
i wrote a custom syncadapter, which also added a custom field to the rawcontacts.
We have a Page that we have given a custom header text field. For
Hi I am working on a custom form field validator, it seems like the
I'm currently working on an Iphone application that has 3 text fields. If I
So I have a custom validator that is working only partially. It basically has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.