Thanks very much to both you and Chris. I managed to work around the
problem, but I think something like what you suggest would have helped.
I'm also thinking the problem may have been on my side, so I don't think
a test case will help. We'll see.
Nick
On Wed, 2002-08-14 at 14:01, Chet Haase wrote:
> There is also a trick to recreating large objects which
> could influence your app:
>
> The code:
>
> BufferedImage img;
> while (true) {
> img = new BufferedImage(w, h, type);
> }
>
> will use up more memory in general than the following:
>
> BufferedImage img;
> while (true) {
> img = null;
> img = new BufferedImage(w, h, type);
> }
>
> The problem with the first approach is the old img is
> still alive (and therefore sitting in the heap) when
> the new image is created, so the allocator must find room
> for the new one without removing the old one.
>
> In the second example, the reference is first removed, so
> when the allocator goes to find enough heap space for the
> new image it is allowed to scavenge the memory from the
> old image first.
>
> I don't know if this is at the root of your problem, but
> I thought it was worth pointing out.
>
> Chet.
>
>
> Chris Campbell wrote:
> >
> > Hi Nick,
> >
> > In general it's best to avoid recreating BufferedImages in an animation
> > loop, but it sounds like you only do it when necessary, which is okay.
> > I'm interested to see why you need to make a larger BufferedImage when
> > you "zoom in". If you send me a small testcase that reproduces the
> > problem I'd be happy to take a look at it.
> >
> > Thanks,
> > Chris
> >
> > Nick Collier wrote:
> > > Hi,
> > >
> > > I think I'm seeing a problem with creating BufferedImage-s and memory
> > > use. To over simplify a bit I'm using one to draw on as part of some
> > > animation. Sometimes I need to recreate it when I've zoomed in (the
> > > BufferedImage needs to become bigger). If I do this enough I eventually
> > > I get an OutOfMemoryError when I try to create the new BufferedImage.
> > > The amount of allocated memory should easily be enough to hold the
> > > largest BufferedImage I need so the problem is not with the size of a
> > > single BufferedImage. I don't have any extraneous references to this
> > > BufferedImage and so the memory should be reclaimed I think. It doesn't
> > > appear to be though. I've come up with a work around that eliminates the
> > > need to recreate the BufferedImage, but I'm still puzzled as to why this
> > > should ever occur, especially as it occurs much more frequently on Win2K
> > > than on Linux.
> > >
> > > I've tried looking in the bug database but it seems to be down.
> > >
> > > Any comments appreciated,
> > >
> > > Nick
> > >
> > > --
> > > Nick Collier
> > > Social Science Research Computing
> > > University of Chicago
> > > http://repast.sourceforge.net
> > >
> > > ===========================================================================
> > > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> > > of the message "signoff JAVA2D-INTEREST". For general help, send email to
> > > [EMAIL PROTECTED] and include in the body of the message "help".
> >
> > --
> > Chris Campbell 408-276-6429
> > [EMAIL PROTECTED] x16429
> > Sun Microsystems, Java 2D USCA22-212
> >
> > ===========================================================================
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> > of the message "signoff JAVA2D-INTEREST". For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
--
Nick Collier
Social Science Research Computing
University of Chicago
http://repast.sourceforge.net
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".