Hello, Will making public and private objects make a differance on Memory management? or this only useful in encapsulating the objects? regards, Arun
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
Access modifiers are only useful for encapsulation purposes. A variable that is declared private and points to some object doesn't want the object it is referencing being garbage-collected... Does it make sense? Only unreferenced objects may be garbage-collected. The following threads contains some pointers to garbage-collection and how the latter works: SCJP Forum: Good resources on Garbage Collection
Hi, Ideally, the data representation of a class is nobody else's business but its own. That way, a client class wouldn't be tempted to directly make use of the data representation. If the data representation is changed in any way (pretty common thing really) the implementing methods of client classes will be unaffected. So make your instance and static variables (and your internal helper methods as well) private unless you really really must. -anthony
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.