2

I have a singleton that I'd like to keep alive for the lifetime of an Application.

public final class KeepAlive extends Whatever {
    private KeepAlive() {}

    private static class Singleton {
        private static final KeepAlive instance = new KeepAlive();
    }
}

Is Singleton.instance considered a strong reference, so that it will not get GC'ed?

UPDATE: Does Android use a custom classloader? Is so, would it ever unload a class like KeepAlive or Singleton?

Eliezer
  • 7,209
  • 12
  • 56
  • 103

1 Answers1

5

The short answer - yes. Once it's created, it will not be garbage-collected.

Mureinik
  • 297,002
  • 52
  • 306
  • 350