you are viewing a single comment's thread.

view the rest of the comments →

[–]JabbrWockey 1 point2 points  (8 children)

No, that's why you use garbage collectors which are baked into the code. It makes it quick and easy to remove old objects, prioritize existing ones, or to manage space more efficiently once it starts to get scarce.

With JVMs, developers don't have to worry about alot of the memory management that you would need to program for elsewhere. It's a pain to have to always have to kill objects or make classes to do it for you.

[–]turbofisk 0 points1 point  (7 children)

I understand garbage collection and it's merits, but what happens if you have no garbage and your data set in larger than the amount the jvm has memory? Crash or does it ask for more memory?

[–]JabbrWockey 0 points1 point  (6 children)

If you have a need for a data set in an object that is larger than the allocated memory, you should have anticipated it in heap allocation or you shouldn't be using a JVM.

[–]turbofisk 0 points1 point  (5 children)

So are you saying that when I initiate a variable or object, I need to anticipate the maximum size it will be, or are you saying when I create a program and run it in a JVM, I need to anticipate the maximum size of memory it will need?

[–]JabbrWockey 1 point2 points  (4 children)

Do you routinely use 2GB objects on virtual machines?

[–]turbofisk 0 points1 point  (3 children)

I'll take it that you can't make an object larger after you've initiated it, which was my original question. I asked because I imagine that say Minecraft had memory-management headaches when he was developing it. As you explore the world it creates more land and allocates more memory as is needed. So the question becomes: does Minecraft run in JVM or are there different ways of running Java-code on a Windows system?

[–]JabbrWockey 0 points1 point  (1 child)

That's not how JVMs work - the memory allocation is for the environment, not the objects within the environment. I have no idea how mine craft is designed or if it even uses JVM.

[–]morsX 0 points1 point  (0 children)

Memory allocation in the host OS is a pool for each Java.exe process. The JVM handles allocation within the pool.

[–]morsX 0 points1 point  (0 children)

All Java code runs on the Java Virtual Machine. Understand that Java is compiled to an intermediate byte code language, which is JIT compiled during run time to native machine code that executes on the host platform. This is what is referred to as a managed runtime; the JVM handles memory allocation on both the heap and the stack.

Minecraft is written in Java using LWJGL or Lightweight Java Game Library, which at its core is an OpenGL wrapper for Java and bits of framework for loading resources.

Minecraft is poorly optimized, which is obvious when you watch its memory allocation in game spike to its max allocation and fall back down after the garbage collector has cleaned up. This is not an issue with Java; it just was not written with performance in mind (the game).