Re: java.lang.OutOfMemoryError
Chuck Hill <[email protected]> Thu, 10 Apr 2003 11:31:42 -0700
| Newsgroups | gmane.comp.web.webobjects.eof |
|---|---|
| Organization | Global Village Consulting, Inc. |
| Message-ID | <[email protected]> |
Look at the docs for NSAutoreleasePool. Wrap the inside of your loops in an
autorelease pool to clean up the temporary objects that you create. You will
need to retain any objects created in the loop that need to live after it.
e.g.
for(j=0;j<BLOQUES;j++){
// create pool
// processing here...
// release pool
}
Chuck
Ricardo Strausz wrote:
> Szia mindenki!
>
> I just recived the following error:
> 2003-04-10 10:50:48.720 Clientes[649] java/lang/OutOfMemoryError
> Stack Trace:
> java.lang.OutOfMemoryError
> <<no stack trace available>>
>
> I have to do some statistics in a not-to-log database (5,000 clients x
> 50,000 invoices) but I am running out of memory... well, from Java's
> point of view, becouse I have 512MB in RAM and 1.3GB in HD, and, at the
> end my disk is equal in size.
>
> Is there some way to assign more memory to the JVM??
>
> Does it uses my VM??
>
> I show down my code; is there an ease way to do it more efficient??
>
> Thanks in advance
> Dino
>
> - (IBAction)monto:(id)sender
> {
> NSArray* nsa = [dgClientes displayedObjects];
> NSEnumerator* en = [nsa objectEnumerator];
> id eo = nil;
> NSArray* facturas = nil;
> int i = 0;
> int j = 0;
> BOOL ok = YES;
> int cambiaron = 0;
> int MESES = [[forma cellAtIndex:0] intValue];
> int BLOQUES = [[forma cellAtIndex:1] intValue];
>
>
> if([nsa count]>0) eo = [en nextElement];
> else return;
> while(eo != nil){
> facturas = [self ordena:[self facturasDe:eo] enBloquesDeTamanyo:MESES
> desde:[NSCalendarDate dateWithString:@"1 1 1996" calendarFormat:@"%m %d
> %Y"]];
> if([facturas count]>BLOQUES){
>
> for(i=0;i<[facturas count]-BLOQUES;i++){
>
> for(j=0;j<BLOQUES;j++){
>
> if([[facturas objectAtIndex:i+j] count]>0) ok = YES;
> else {
> ok = NO;
>
> break;
> }
> }
> if(ok){
> [eo setGrupo:[NSNumber numberWithInt:MESES]];
> cambiaron++;
> break;
> }
> }
>
>
> }
> NS_DURING
> eo = [en nextElement];
> NS_HANDLER
> eo = nil;
> NS_ENDHANDLER
> }
> [[forma cellAtIndex:2] setIntValue:cambiaron];
> }
>
> - (NSArray*)facturasDe:(id)eo
> {
> NSString* nss = [NSString stringWithFormat:@"cliente=%@ and
> estado>0",[eo folio]];
> id eoq = [EOQualifier qualifierWithQualifierFormat:nss:nil];
> NSArray* nsa = nil;
>
> [[dgFacturas dataSource] setAuxiliaryQualifier:eoq];
> [dgFacturas fetch:self];
> nsa = [dgFacturas displayedObjects];
> return nsa;
> }
>
> - (NSArray*)ordena:(NSArray*)nsa
> enBloquesDeTamanyo:(int)meses
> desde:(NSCalendarDate*)desde
> {
> NSMutableArray* nsmaa = [NSMutableArray array];
> NSMutableArray* nsmab = [NSMutableArray array];
> NSCalendarDate* nscda = desde;
> NSCalendarDate* nscdb = [nscda dateByAddingYears:0
> months:meses
>
> days:0
>
> hours:0
>
> minutes:0
>
> seconds:0];
> NSEnumerator* en = [nsa objectEnumerator];
> id eo = nil;
> NSCalendarDate* eoFecha = [NSCalendarDate alloc];
>
> if([nsa count]>0) eo = [en nextElement];
> else return nsmaa;
> while(eo != nil){
> [eoFecha initWithString:[[[eo fecha] toString] substringToIndex:11]
>
> calendarFormat:@"%Y-%m-%d"];
> if([[eoFecha laterDate:nscda] isEqual:eoFecha]
> && [[eoFecha laterDate:nscdb] isEqual:nscdb]){
> [nsmaa addObject:eo];
> NS_DURING
> eo = [en nextElement];
> NS_HANDLER
> eo = nil;
> NS_ENDHANDLER
> } else {
> [nsmab addObject:nsmaa];
> nsmaa = [NSMutableArray array];
> nscda = nscdb;
> nscdb = [nscda dateByAddingYears:0
> months:meses
>
> days:0
>
> hours:0
>
> minutes:0
>
> seconds:0];
> }
> }
> [eoFecha release];
> return nsmab;
> }
>
--
Chuck Hill [email protected]
Global Village Consulting Inc. http://www.global-village.net