I think there could be a couple of metrics for limiting the cache size: maximum elements, or maximum size (which would require keeping track of object sizes, which could be tricky). And both of these would probably require an LRU list for throwing out the ones that aren't being used frequently (which isn't in there at the moment either).
Some documentation would definitely help to understand the issues. ~Roger Whitcomb -----Original Message----- From: Sandro Martini [mailto:[email protected]] Sent: Thursday, July 19, 2012 5:15 AM To: [email protected] Subject: Re: OutOfMemoryError - after calling ImageView.setImage(url) 50 times Hi all, Roger (and others) what do you think if for the 2.1 release we could implement a max number of elements for that cache (and then maybe even for some Pivot collections) ? Other useful methods for Pivot collection are already planned for 2.1 ... So in this way we could avoid errors like these ... Anyway maybe we (or I) could add (both for 2.0.3, and 2.1) come javadoc comment in rsourceCache get/set to avoid outofmemory issues ... Bye, Sandro 2012/7/18 Roger L. Whitcomb <[email protected]>: > Actually, I think I see what's going on: > > * Every time you load an image it is saved in the ApplicationContext > resource cache so it can be retrieved quickly if it is reused. > > * There is no provision for limiting the size of that cache, so the > cache continues to grow as it caches each of the images in your slideshow. > > > > So, the solution is simple: save the URL of the previous image and > before doing the "setImage" of the new one, remove the old one from > the cache like > this: > > > > ApplicationContext.getResourceCache().remove(previousURL); > > > > HTH, > > ~Roger Whitcomb > > > > From: Roger L. Whitcomb [mailto:[email protected]] > Sent: Wednesday, July 18, 2012 2:12 PM > To: [email protected] > Subject: RE: OutOfMemoryError - after calling ImageView.setImage(url) > 50 times > > > > Hi Sridhar, > > How is the ImageView being displayed in Pivot? How > exactly does the update to the next image occur? Someone else logged > a bug about images used as window icons not being released in the > image listener list, so this sounds a lot like the same problem. > > So, could you provide a small sample program that > demonstrates the problem? One of us will be looking at the problem. > > > > Thank you for using Pivot, > > ~Roger Whitcomb > > > > From: Sridhar Sarnobat [mailto:[email protected]] > Sent: Wednesday, July 18, 2012 2:03 PM > To: [email protected] > Subject: OutOfMemoryError - after calling ImageView.setImage(url) 50 > times > > > > I have created a slideshow application using Apache Pivot, and it > works great. > > > > But it reaches 285 MB after I cycle through about 50 jpg images, and > starts throwing OOM errors. I have a memory leak that I don't know how > to stop. I am manipulating java.io.File objects (not streams or > readers) and I don't see any way to close these files. > > > > I believe that I am not releasing resources of a File 1 before calling > the following line with File 2: > > > > org.apache.pivot.wtk.ImageView.setImage( > java.io.File.toURI().toURL() ) > > > > I hope that's enough information. What am I doing wrong? I don't want > to increase the available heap space. This is supposed to be a simple app.
