Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heap memory problems

There's a WCF self hosted service that must work 99% of time. Sometimes we got some memory troubles like this:

memory leaks

But service is working as usual after that issues. How can we manage this? Any tips and points to make robust services that will survive in different except situations are very very welcome.

like image 890
kseen Avatar asked Sep 28 '11 03:09

kseen


People also ask

What happens if heap memory is full?

When the heap becomes full, garbage is collected. During the garbage collection objects that are no longer used are cleared, thus making space for new objects.

What is heap size issue?

Java Heap space is one of the most common errors when it comes to memory handling in the Java Virtual Machine world. This error means that you tried to keep too much data on the heap of the JVM process and there is not enough memory to create new objects, and that the garbage collector can't collect enough garbage.

How do I free up heap space?

The heap is cleared by the garbage collector whenever it feels like it. You can ask it to run (with System. gc() ) but it is not guaranteed to run.

Can heap run out of space?

In a word, yes, it can. While the heap can grow and shrink, it does have lower and upper bounds (usually defined by the -Xms and -Xmx arguments, unless you choose to se the defaults). If the heap size is exceeded, the allocation will fail and you'll get a java.


1 Answers

I am not too sure where the problem resides but memory leaking can be a reason.

All code is managed. And we use dotConnect for Oracle from devArt as data layer library.

You assume all code is managed, but there can be unmanaged parts. However, you must call the Dispose method for all the disposable objects after using them, don't think they are properly dispose once they go out of scope. The best practice is, not to let Disposable objects to go out of scope without calling their Dispose method. You may be able to use 'using' statements if you are using them as local variables.

DbConnection is a good example for disposable objects, make sure you dispose all the connections (disposable objects).

like image 89
CharithJ Avatar answered Oct 20 '22 03:10

CharithJ