tags:

views:

113

answers:

4

This may be a bit off topic of "right answer, not discussion."

However, I am trying to debug my thought process, so maybe someone can help me:

I use compilers all the time, and the fact that I'm giving up control over machine code generation (the layout of my caches, and the flow of electrons) does not bother me.

However, giving up control of memory layout (being able to place stuff in memory) and memory management (garbage collection) still bothers me these days.

Have others dealt with this? If so, how did you get past it? (In particular, how I often feel "safer" in C++ than in Java.)

Thanks!

+4  A: 

Your feeling is, naturally, very subjective.

You might feel comfortable managing your own memory space in C++. Others might appreciate the easiness of Java managing the heap for you, and reducing memory management overhead to a minimum.

Programming domain has an influence as well. For example, in an embedded environment, you most likely will not have the privilege to enjoy a garbage collection mechanism, leaving you to manage your own memory, whether you like it or not.

Bottom line - subjective and domain-dependent.

Yuval A
+1  A: 

If you trust the JVM with code generation, why not trust it with data generation too?

Please note that things like cache sizes on CPU may influence the optimal placement of your objects, and that the JIT basically knows better than you because it can measure and take action in the process.

Thorbjørn Ravn Andersen
Why not trust it with data generation? http://www.cs.virginia.edu/kim/publicity/pldi09tutorials/memory-efficient-java-tutorial.pdf might be a possible answer to that. ;) Although that is less the JVM's fault than the Java language and class library
jalf
+1  A: 

If you've ever used COM under C++ its really no different to using "Release()". The momory may or may not be freed right then or it may be freed somewhere down the line when the thing using it has finished using it.

Best thing to do is just assume it works and stop worrying about it.

Goz
+2  A: 

Confront your nightmare! Profile a busy application in NetBeans and watch the garbage collector do its job. profile

trashgod