Can someone explain the difference between on-heap memory and off-heap memory?Does the off-heap memory show on the JVM memory size?Are the off-heap all pointers?
All memory is native memory, however the JVM manages and record memory in it's JVM heap (not the same as the native heap)
Offheap is a Java term for memory not managed directly. However, it can be managed indirectly using direct ByteBuffer(s) as proxy objects for raw native memory.
Related
Allocate memory on heap is an expensive operation and so some programming languages avoid to give it back to the operating system, even if the allocated memory is not being used anymore.
But for many scenarios, for example microservices running on cloud, you would to like to have low memory usage, otherwise the bill can be quite high.
So in these cases it's really important to release the memory after it is not being used.
What is Rust default strategy to uncommit and return memory to the operating system?
How can that be changed?
By default Rust uses the system allocator.
This is based on malloc on Unix platforms and HeapAlloc on Windows, plus related functions.
Whether calling free() actually makes the memory available to other processes depends on the libc implementation and your operating system, and that question is mostly unrelated to Rust (see the links below). In any case, memory that was freed should be available for future allocations, so long-running processes don't leak memory.
My general experience is that resource consumption of Rust servers is very low.
See also:
Does free() unmap the memory of a process?
Why does the free() function not return memory to the operating system?
Will malloc implementations return free-ed memory back to the system?
Allocate memory on heap is an expensive operation and so some programming languages avoid to give it back to the operating system, even if the allocated memory is not being used anymore.
But for many scenarios, for example microservices running on cloud, you would to like to have low memory usage, otherwise the bill can be quite high.
So in these cases it's really important to release the memory after it is not being used.
What is Rust default strategy to uncommit and return memory to the operating system?
How can that be changed?
By default Rust uses the system allocator.
This is based on malloc on Unix platforms and HeapAlloc on Windows, plus related functions.
Whether calling free() actually makes the memory available to other processes depends on the libc implementation and your operating system, and that question is mostly unrelated to Rust (see the links below). In any case, memory that was freed should be available for future allocations, so long-running processes don't leak memory.
My general experience is that resource consumption of Rust servers is very low.
See also:
Does free() unmap the memory of a process?
Why does the free() function not return memory to the operating system?
Will malloc implementations return free-ed memory back to the system?
I'm studying about operating systems currently and I am a bit confused.
When a process is started for the first time, does the OS know the size of the heap? (I am guessing it knows the size of the data & code segments)
Heap is just a concept. There is no real, single heap. A heap is a block of memory that can be used for dynamic memory requests. A heap is created by library routines that allocate dynamic memory. There can be many heaps or no heap at all.
The OS never knows the size of the process heap.
I have this memory issue with Java 8 on Jetty Server. After exploring about memory leaks, it is not clear for me that: whether a Java Memory leak will cause just jvm OutOfMemoryError only? or can cause excessive physical memory usage(which can't be tracked by profiler) resulting a system crash?
A memory leak can lead to any resource being exhausted.
A common one is running out of file descriptors, i.e. files or keeping unused sockets alive. This limit can be as low as 1024.
It would be possible to do the same thing with GUI components or any component which proxies an external resource.
Is memory allocated by JVM , & where all the data stored in RAM or Hard-disk. Or memory allocated by constructor, if yes then how memory allocated of static class members.?
JVM creates a memory area called 'The Heap' on startup where all of the application memory goes. This is created in RAM and is garbage collected when full. See the Memory Management documentation for details -> Understanding Memory Management
Roughly, there are different kinds of allocations: object data (reference types) is stored in so called heap, primitive data and object pointers are stored on stack. Both stack and heap are in RAM, in a JVM process memory area.
Effectively, object allocations are done by constructor, or, more specifically, new call.
This awesome article explains allocations in a more precise and correct way.