When vectors are allocated, do they use memory on the heap or the stack?

vector<Type> vect; will allocate the vector, i.e. the header info, on the stack, but the elements on the free store (“heap”). vector<Type> *vect = new vector<Type>; allocates everything on the free store. vector<Type*> vect; will allocate the vector on the stack and a bunch of pointers on the free store, but where these point is … Read more

How to find Java Heap Size and Memory Used (Linux)?

Each Java process has a pid, which you first need to find with the jps command. Once you have the pid, you can use jstat -gc [insert-pid-here] to find statistics of the behavior of the garbage collected heap. jstat -gccapacity [insert-pid-here] will present information about memory pool generation and space capabilities. jstat -gcutil [insert-pid-here] will … Read more

Why are two different concepts both called “heap”? [duplicate]

Donald Knuth says (The Art of Computer Programming, Third Ed., Vol. 1, p. 435): Several authors began about 1975 to call the pool of available memory a “heap.” He doesn’t say which authors and doesn’t give references to any specific papers, but does say that the use of the term “heap” in relation to priority … Read more

Stack vs heap allocation of structs in Go, and how they relate to garbage collection

It’s worth noting that the words “stack” and “heap” do not appear anywhere in the language spec. Your question is worded with “…is declared on the stack,” and “…declared on the heap,” but note that Go declaration syntax says nothing about stack or heap. That technically makes the answer to all of your questions implementation … Read more

What is memory fragmentation?

Imagine that you have a “large” (32 bytes) expanse of free memory: ———————————- | | ———————————- Now, allocate some of it (5 allocations): ———————————- |aaaabbccccccddeeee | ———————————- Now, free the first four allocations but not the fifth: ———————————- | eeee | ———————————- Now, try to allocate 16 bytes. Oops, I can’t, even though there’s nearly … Read more

How do I analyze a .hprof file?

If you want a fairly advanced tool to do some serious poking around, look at the Memory Analyzer project at Eclipse, contributed to them by SAP. Some of what you can do is mind-blowingly good for finding memory leaks etc — including running a form of limited SQL (OQL) against the in-memory objects, i.e. SELECT … Read more

Increase heap size in Java

You can increase to 2GB on a 32 bit system. If you’re on a 64 bit system you can go higher. No need to worry if you’ve chosen incorrectly, if you ask for 5g on a 32 bit system java will complain about an invalid value and quit. As others have posted, use the cmd-line … Read more

java.lang.OutOfMemoryError: GC overhead limit exceeded [duplicate]

You’re essentially running out of memory to run the process smoothly. Options that come to mind: Specify more memory like you mentioned, try something in between like -Xmx512m first Work with smaller batches of HashMap objects to process at once if possible If you have a lot of duplicate strings, use String.intern() on them before … Read more

Java heap terminology: young, old and permanent generations?

This seems like a common misunderstanding. In Oracle’s JVM, the permanent generation is not part of the heap. It’s a separate space for class definitions and related data. In Java 6 and earlier, interned strings were also stored in the permanent generation. In Java 7, interned strings are stored in the main object heap. Here … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)