static Objects/Variables considered loosers because they finish last
Encapsulation is one of the cornerstones of good OOP; it keeps objects from interfering with another and generally reduces complexity and dependencies. The static keyword on the other hand, is a memory trap waiting to happen, if your not careful. Normally when an object is created its constructor is called and all its members constructors are called. Eventually, when it goes out of scope, their destructors are called. When you declare a static object, it sticks around; the destructor isn't called until the end of the program. This may be okay if done on a small scale with small objects but if you're not aware of the ramifications, and you use static objects with large amounts of memory, you may be consuming alot more memory then you need to be. Note, the scope of the object is still limited but its memory usage is not.

0 Comments:
Post a Comment
<< Home