Click here to Skip to main content
15,886,860 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What you have told previously is reminded by you and that's true plus one more problem of using static variable is that after it is called it remains active in memory or to say it just occupies space in memory as long as the program is running....
It's also true that I should have a very good reason to use static.
Sir if I explicitly give a null value to it then I think the space taken by the variable is freed ... And the program will have no performance problem...am I right sir.. ?

What I have tried:

I I have tried to just increase my knowledge over static.
Posted
Updated 9-Feb-21 4:24am
Comments
PIEBALDconsult 9-Feb-21 10:10am    
I think you need to study references more deeply. A reference to an object is not the object itself.
An object in memory doesn't know whether it has references which are static or not.
Once all references to the object have been removed (such as setting to null) it can be garbage collected -- whether or not those references were static is immaterial.
Member 12712527 9-Feb-21 10:20am    
This static can only be garbage collected once it is freed but if it remains active all the time until the program ends I hope it isn't garbage collected so there is a performance problem. . maybe I think
PIEBALDconsult 9-Feb-21 10:34am    
No, do not think of the object itself as static, it isn't, it's just an object, it can have many references, some may be static and others not.
Member 12712527 9-Feb-21 10:40am    
An object in memory maybe static may not be but my question is that as only in the case of static I am thinking that as it remains active all the time in memory until the program ends it is not garbage collected which may lead to performance problem is it right sir
PIEBALDconsult 9-Feb-21 10:53am    
No, do not think of the object itself as static, it isn't, it's just an object, it can have many references, some may be static and others not.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900