Welcome to the new Gigaspaces XAP forum. To recover your account, please follow these instructions.

Ask Your Question

ReadIfExists memory leak?

Hello. I'm use Gigaspaces 7.1.1 and Java 1.6.0_17 on Linux. And in my project I use SOAP service, which use remote tasks, which read objects from space and return results. For additional - I'm use the mirror service for initial load POJO from database and use SQL Query for read objects from space. And when I write application for testing handle requests - I see, what memory, which gigaspaces uses - is grown(about 1-1,5 Gb). I'm use 10 threads, which do the requests 100000 requests for each.

Objects, which growns(I see it on YourKit profiler): 1. char[] 2. java.lang.String 3. java.util.concurrent.ConcurrentHashMap$HashEntry[] 4. java.util.concurrent.locks.ReentrantLock$NonfairSync 5. java.util.concurrent.ConcurrentHashMap$Segment 6. com.j_spaces.jdbc.SelectColumn 7. com.j_spaces.jdbc.query.QueryColumnData

When I execute Full GC after test(I'm use "jmap -histo:live" command for that) - memory is not reduced. I'm attached screenshot with my profiling(percentage shows how each method created objects). Please, ignore the the black area - it's just our service calls. h4. Attachments

[Screenshot from 2013-04-05 18-39-55.png|/upfiles/13759701936648655.png]

{quote}This thread was imported from the previous forum. For your reference, the original is [available here|http://forum.openspaces.org/thread.jspa?threadID=4060]{quote}

asked 2013-04-11 13:01:55 -0600

ssherbakov gravatar image

updated 2013-08-08 09:52:00 -0600

jaissefsfex gravatar image
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

How the readIfExists call looks like? What's the timeout value?
Do you have transactional operations? Any special reason why you use readIfExists and not read?

Do you see the problem with XAP 9.5?

answered 2013-04-11 18:42:04 -0600

shay hassidim gravatar image
edit flag offensive delete link more


  I'm easy call readIfExists in "for loop" for 10 threads. In space I have 4,5 millions entries. I'm not use the transaction and timeout is 0 value.
For now I'm use sql query for read entries from space and have memory leaks. But when I change sql query template to object template - the problem is gone.

ssherbakov gravatar imagessherbakov ( 2013-04-13 15:43:13 -0600 )edit

Are you using parameterized (with '?' and setParameter() methods) queries or string queries?


SQLQuery<pojo> query = new SQLQuery<pojo>("id = 'myId'")


SQLQuery<pojo> query = new SQLQuery<pojo>("id = ?) query.setParameter(1,"myId")

If you are using the first case, there is a known issue that if on each read you put a new string value on the properties there is a memory leak. You should use the second way with the parameters.


eitany gravatar imageeitany ( 2013-04-13 15:56:23 -0600 )edit

  I'm use SQLQuery<Pojo> query = new SQLQuery<Pojo>(Pojo, "id = 'myId'");
But if this is known problem - why is not resolved?

ssherbakov gravatar imagessherbakov ( 2013-04-13 16:04:54 -0600 )edit

For now I'm execute SQLQuery<pojo> query = new SQLQuery<pojo>("id = 'myId'") for each thread and each iteration. For exclude memory leak - I need to use predefined SQLQuery(for example - "private static final SQLQuery<pojo> query = new SQLQuery<pojo>("id = ?")") or I need to use predefined Strings and on each iteration I may create new SQLQuery, but use constants strings?

ssherbakov gravatar imagessherbakov ( 2013-04-14 09:46:05 -0600 )edit

The second option, using predefined strings.

There is internal mechanism to cache SQLQuery according to their string not the actual SQLQuery instance in memory, this is an optimization that reduces the need to parse the string every time and reduce the need construct the syntax tree for every query. So if on each iteration you use a different string, the caching is redundant and the tree is parsed and created and cached everytime (there might be a leak in that case).

But regardless of the potential leak, you should not use on each iteration a different string if its syntax is the same and only the values are different since you are losing the advantage of the optimization. You should always use the parameterized form to gain this benefit unless your query is always with the same values, which I guess is not your case otherwise you wouldn't encounter this issue.

Hope this helps


eitany gravatar imageeitany ( 2013-04-14 09:56:59 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2013-04-11 13:01:55 -0600

Seen: 90 times

Last updated: Apr 11 '13