So You’ve Heard of ‘Static’

Statics must be judicially used. And that too very carefully. One must be very clear of the implementation and must have all the below mentioned points in mind.

Reasons why one shouldn’t use statics-

1. They are a permanent resident of the memory stack.

2. They are initialized when the container class initializes.

3. Since they remain forever, they easily lead to memory leaks.

If you must use statics, for certain very strong reasons. You must use it with final modifier.

Using with mutable objects may cause the following problems – 

1. Frequent memory leaks

2. Also, when working in a threaded environment, using mutable may result in peculiar results unless handled properly.

Advertisements

About Gaurav

I'm Gaurav; friends call me Teddy, n i'm shivi fr my family!! A java enthusiast who likes experimenting with what he knows. View all posts by Gaurav

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: