DKSRathore
DKSRathore

Reputation: 3063

What and how much overheads happen when I use a Reference class?

I saw there is a daemon thread running whenever we create a referenced object using any Reference class like

 WeakReference, 
 FinalReference, 
 SoftReference, 
 PhantomReference,
 Referemce

And if we have hierarchal thread structure then at each level there is an extra daemon thread initiated.

Upvotes: 1

Views: 169

Answers (2)

Carl Smotricz
Carl Smotricz

Reputation: 67760

The only way I see this becoming a problem is if your number of threads grows well into 2 digits and more.

Very roughly speaking:

  • 10 threads will be next to unnoticeable
  • 100 should be OK, since they're mostly just waiting and chewing up a bit of memory each
  • 1000 will give your system a headache because those resources will be missing elsewhere
  • 10000 will bring your system to its knees, if not outright kill it.

Upvotes: 1

Peter Lawrey
Peter Lawrey

Reputation: 533530

I would expect the overhead to be very small for most applications. Unless you know it is a problem I wouldn't worry about it. I have never seen references show up as an issue in a profiler and I have been using different profilers for 10 years.

Upvotes: 2

Related Questions