Re: Out of memory
Re: Out of memory
- Subject: Re: Out of memory
- From: Chuck Hill <email@hidden>
- Date: Wed, 28 Nov 2007 10:36:11 -0800
On Nov 28, 2007, at 5:38 AM, Miguel Arroz wrote:
Hi!
I'm having an Out of memory exception (and consequently
application death) that I can't figure out why it happens. I
suspect it's because I'm assuming something about the WO behaviour
that is not correct (as usual).
The ways of WO are many and mysterious. :-)
The problem is this: I have an action that creates some test
data. Depending on the parameters I feed on the page, it may create
many many objects (50k, or more).
Generally, EOF sucks at this. Bulk data is not its strong point.
Of course, this takes time, and the request will at some point hang
(ie, the browser gets an error from the adaptor) but I don't care,
as this is used only during testing.
The problematic part of the code is something like this:
for( int i = 0; i < numberOfObjectsToCreate; i++ ) {
EOEditingContext theContext = ERXEC.newEditingContext();
theContext.lock();
Not your problem, but I would add
theContext.setUndoManager(null);
// Create stuff here
Is anything outside of this loop keeping a reference (a
relationship?) to these objects?
theContext.saveChanges();
theContext.unlock();
theContext.dispose();
if( i % 50 == 0 ) {
NSLog.out.appendln("Generating object " + i + "...");
}
}
The "Create stuff here" creates and updates a few objects,
nothing very heavy.
The problem is that, if numberOfObjectsToCreate is too big, this
starts getting slower and slower (more time passes between the log
lines) until it eventually blows up with Out Of Memory. Currently
it's dying when i is about 3100, which is not a very impressive
number.
No, not impressive at all.
My assumption is that on every cycle, all the objects I created
in the context are saved and then garbage collected. Obviously that
doesn't seem to be happening. So:
1) Why? (I know I know, this is a good candidate for the "How to
ask smart questions", but here it goes anyway)
:-P Other than something outside the loop keeping a reference to
them, I don't know. And even then, 3100 is not exactly a large
number to keep around.
2) How can I debug this? How can I know what objects are not
being GCed and why?
The first thing I would try is to add this after the "Generating
object " NSLog:
EOEditingContext.defaultParentObjectStore().invalidateAllObjects();
I am curious if that changes anything.
Other than that, I'd try something like Shark (Xray now?).
Chuck
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden