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 7950373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:15:02+00:00 2026-06-04T02:15:02+00:00

This is not my code. I just arrived at this site and am doing

  • 0

This is not my code. I just arrived at this site and am doing code review.

They have a class which is an extension of Dialog.
It has been defined as a singleton.

On the first call the context is passed to the getInstance method.
It instantiates the class passing the received context to the “super” within the constructor.
Then it saves it – same as in any singleton.

It then displays the dialog. After user interaction it starts a new activity and closes the dialog via “closeDialog”.

However, it is still alive since the static holder for the instance is still there.
Will this then hold on to the activity that created it (and was passed on the “getInstance” call and into the “super()” when creating the instance)?

They keep the instance alive because they then use it for calls from other places and have values that need to be carried over.

I know this code stinks but I want to be sure that it does leak memory (the first activity) before I make them re-write it (or re-write it myself – which is more likely).

  • 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-04T02:15:03+00:00Added an answer on June 4, 2026 at 2:15 am

    Yes it could. If the code starts other activities, then yes. If only the one activity is ever used, then most likely not. The reason being, dialogs must be instantiated with an activities context (it’ll crash with the Application context). If that activity is set to be destroyed, garbage collection won’t clean it up until all references to it are destroyed. If this singleton dialog lives outside the activity (which should be the case), then it’ll continue referencing the activity and prevent GC from cleaning it up. You can read more about leaking contexts here: Avoiding memory leaks

    As you stated the code is bad, and using a singleton dialog like that is just plain wrong (whether it leaks or not). There are better ways of maintaining data between states.

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

Sidebar

Related Questions

I have some code which is like this (This is not production code. Just
I just recently found myself writing this line of code, which i did not
I just found my code like this does not compile right? Is there any
I'm trying to solve this problem, its not a homework question, its just code
I've got this image: I want to code this image (just the bar, not
Why does this code not print an exception stack trace? public class Playground {
Why this code does not compile (Cygwin)? #include <vector> template <class Ttile> class Tilemap
I have an class which should send/receive data in packet form. This class contains
I'm doing something very simple that's just not working. I have an html page
I want to know i can do something similar to this (not working) code

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.