You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Mattex83 <ma...@abodata.com> on 2009/11/19 15:33:40 UTC

ObjectStore OutOfMemory Exception

Hi,

I've a memory trouble using the last version of Cayenne ( v3.0b). I created
a table to store data coming with a frequency of 10-20 record per second.
After few hours my application run out of memory.

Heap report says that there are about 15000 records (and 15000 ObjectId)
referenced by my application.

This app hasn't any hashmap or list of records (it just creates persistent
objects) so I think that these records are stored in ObjectStore.

On commit I print these info:

log.info("Registered Count:
"+context.getObjectStore().registeredObjectsCount());
log.info("New Count: "+ context.newObjects().size());
log.info("Delete Count: "+ context.deletedObjects().size());
log.info("Modify Count: "+ context.modifiedObjects().size());
log.info("Cache Size: "+context.getQueryCache().size());

the first one raise on each commit other logs are 0.
So I think that context keeps committed objects, but I understood that v3.0
shouldn't do this...

How can I avoid this? or How can I clear the context registered Objects?

my add function is:

public void AddPacket(Integer serviceType, Date startTime, Date
arrivalTime){
		
		Packet p = (Packet) context.newObject(Packet.class);

		p.setServiceType(serviceType);
		p.setStartTime(startTime);
		p.setArrivalTime(arrivalTime);

		try{
			context.commitChanges();
		}
		catch(ValidationException e){
			log.warn("Validation failed. Packet discarded\n");
			try{
				context.rollbackChanges();
			}
			catch(Exception e1){
				e1.printStackTrace();
			}
		}
		catch(Exception e){
			e.printStackTrace();
			try{
				context.rollbackChanges();
			}
			catch(Exception e1){
				e1.printStackTrace();
			}
			
		}
		log.info("Registered Count:
"+context.getObjectStore().registeredObjectsCount());
		log.info("New Count: "+ context.newObjects().size());
		log.info("Delete Count: "+ context.deletedObjects().size());
		log.info("Modify Count: "+ context.modifiedObjects().size());
		log.info("Cache Size: "+context.getQueryCache().size());
		context.getObjectStore().getDataRowCache().clear();
		context.getQueryCache().clear();
}


Thanks in advance


Matteo
-- 
View this message in context: http://n3.nabble.com/ObjectStore-OutOfMemory-Exception-tp36832p36832.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: ObjectStore OutOfMemory Exception

Posted by Mattex83 <ma...@abodata.com>.

Thank you but I solved in another way :)

Yesterday I posted an incomplete example code. it doesn't show a relation
between object Packet and object Device (sender and receiver of the packet).

Without this relation, garbage collection works properly and the committed
objects are collected.


Thanks


Matteo



-- 
View this message in context: http://n3.nabble.com/ObjectStore-OutOfMemory-Exception-tp36832p37486.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: ObjectStore OutOfMemory Exception

Posted by Michael Gentry <mg...@masslight.net>.
Do you need your objects to live in "context" for an extended period?
Could you do this instead?

public void AddPacket(Integer serviceType, Date startTime, Date arrivalTime){
    DataContext context = DataContext.createDataContext();
    Packet p = (Packet) context.newObject(Packet.class);
    ...
}

That will allow the context to be garbage collected (if that will work
with your code).

mrg


On Thu, Nov 19, 2009 at 9:33 AM, Mattex83 <ma...@abodata.com> wrote:
>
> Hi,
>
> I've a memory trouble using the last version of Cayenne ( v3.0b). I created
> a table to store data coming with a frequency of 10-20 record per second.
> After few hours my application run out of memory.
>
> Heap report says that there are about 15000 records (and 15000 ObjectId)
> referenced by my application.
>
> This app hasn't any hashmap or list of records (it just creates persistent
> objects) so I think that these records are stored in ObjectStore.
>
> On commit I print these info:
>
> log.info("Registered Count:
> "+context.getObjectStore().registeredObjectsCount());
> log.info("New Count: "+ context.newObjects().size());
> log.info("Delete Count: "+ context.deletedObjects().size());
> log.info("Modify Count: "+ context.modifiedObjects().size());
> log.info("Cache Size: "+context.getQueryCache().size());
>
> the first one raise on each commit other logs are 0.
> So I think that context keeps committed objects, but I understood that v3.0
> shouldn't do this...
>
> How can I avoid this? or How can I clear the context registered Objects?
>
> my add function is:
>
> public void AddPacket(Integer serviceType, Date startTime, Date
> arrivalTime){
>
>                Packet p = (Packet) context.newObject(Packet.class);
>
>                p.setServiceType(serviceType);
>                p.setStartTime(startTime);
>                p.setArrivalTime(arrivalTime);
>
>                try{
>                        context.commitChanges();
>                }
>                catch(ValidationException e){
>                        log.warn("Validation failed. Packet discarded\n");
>                        try{
>                                context.rollbackChanges();
>                        }
>                        catch(Exception e1){
>                                e1.printStackTrace();
>                        }
>                }
>                catch(Exception e){
>                        e.printStackTrace();
>                        try{
>                                context.rollbackChanges();
>                        }
>                        catch(Exception e1){
>                                e1.printStackTrace();
>                        }
>
>                }
>                log.info("Registered Count:
> "+context.getObjectStore().registeredObjectsCount());
>                log.info("New Count: "+ context.newObjects().size());
>                log.info("Delete Count: "+ context.deletedObjects().size());
>                log.info("Modify Count: "+ context.modifiedObjects().size());
>                log.info("Cache Size: "+context.getQueryCache().size());
>                context.getObjectStore().getDataRowCache().clear();
>                context.getQueryCache().clear();
> }
>
>
> Thanks in advance
>
>
> Matteo
> --
> View this message in context: http://n3.nabble.com/ObjectStore-OutOfMemory-Exception-tp36832p36832.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.
>