Image Caching With JList

Hi all, I need to know, how can I implement an Image Cache feature with a JList that is effective, ie. basic I would like the images to be stored in memory when the list is visible (done that already using a WeakHashMap<String, Icon>) and removed from memory when the JList is not displayed.
Currently I use the following code section, to try and remove the data from memory, seems not work according to task manager. Sorry I cannot seem to come up with a good SSCCE since I'm not exactly sure how to make an example that loads images. Any suggestion with that?
WeakHashMap<String,Icon> icons = new WeakHashMap<String,Icon>();
JList list = new JList(); // something like this in actual code
public void startClearTimer() {
    new javax.swing.Timer( 30000, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if(!list.isShowing() && icons.size() > 0 ) {
                resetIconCache();
                System.out.println("Icons Cleared");
                System.gc();
                //((javax.swing.Timer)e.getSource()).stop();
    }).start();
public void resetIconCache() {
    if(icons == null) {
        return;
    Iterator<Icon> images = icons.values().iterator();
    while(images.hasNext()) {
        ImageIcon icon = (ImageIcon)images.next();
        icon.getImage().flush(); // smoke but no cigar
        icon = null;
    icons.clear();
    icons = new WeakHashMap<String,Icon>();
}This code is used in a ListCellRenderer, which loads the images, scales them, caches them in memory so the repaints are faster and displays them along side some JLabels.
So basically how can I load the images in memory and release the resources used when the images are not required?
ICE

you can't be cleverer than JVM for memory usage.
Of course you can, because the point of caching is that it requires (or at the very least is optimised by) some understanding of the use case. JVMs are somewhat unlikely to predict how any given set of users will use any given application, nor are they capable of factoring in the cost of downloading (or otherwise obtaining) data which has been freed from memory. To a JVM, a lump of voidable memory is no different to any other.
Take an example of an applet (which is limited to 96Mb of heap) which browses images on a server. Let's say it's looking at images which occupy 20Mb of memory each (far from unreasonable) in memory. They might each be 1Mb or so in compressed file size, which is an appreciable delay in download time.
Each time the user switches between images, the applet will probably want to implement a policy that says "that last image should be kept in memory if possible, since the user might return to it and they won't want another long delay to load it, but if you run out of memory downloading the next image, feel free to discard the first, because the next is more important." (Furthermore, your workflow might permit you to prioritise images.)
In order to indicate to the JVM that the first image is disposable, you must clear all strong references to it. However, this simply makes it eligible for garbage collection: simple as that. You have no control over whether the garbage collector will clean that image data (which takes several seconds to retrieve) or a bunch of other data which is completely useless or can be recreated in milliseconds. Also note that in practice, weak and soft references do not actually encourage the GC to retain the data: it is cleared long before the memory is actually required.
Note, too, that the suggestion of tweaking the heap allocation is no use for an applet (unless you have a very small, very knowledgeable and very tolerant user base).

Similar Messages

  • Image cache not working with Firefox and apex

    Hi,
    I'd like to cache all my images to save page rendering time and bandwidth because my images are all static and never change.
    I use the John Scott's caching technique Link: [http://jes.blogs.shellprompt.net/2007/05/18/apex-delivering-pages-in-3-seconds-or-less/], in a few words this technique consists of adding a header line "Expires: date in the future" in the http response.
    It works very well in IE, the images are cached and the same image can be accessed several times (within the same session or in different sessions) without issuing an http request to the server each time.
    with Firefox it does not work, the same image is asked again and again to the server (i'm using FF 3.5 and APEX 3.2).
    - Is it a date format problem? no, because when i type about:cache in FF, i can find my image in the cache with an expire date in the future.
    The weird thing here is that the counter is incremented each time u request the image, so FF knows it is in the cache and even if the expire date is in the future, FF asks it again to the server.
    - Is it a FF bug? If u read the http specs or if u google a little, u can come to the conclusion that FF does not follow the standards,
    but... images.google.com for example manages to get its images cached with FF.
    They use an http response header "cache-control: public, max-age=604800".
    I tried the same and all kinds of combinations but without success.
    When i compare my image with the one from google in the FF cache, they both have the same attributes.
    - It's not an apex issue neither because it works with IE, most probably an incompatibility between apex and FF?
    Maybe the use of cookie? or the http request (not the response) containing "cache-control: max-age=0"?
    I've found so far 2 half solutions:
    1) use ETag and modified date, see the Tyler Muth's note Link: [http://tylermuth.wordpress.com/2008/02/04/image-caching-in-plsql-applications/].
    with this technique FF continues to send request each time but the answer is shorter because it's just a "304 not modified" instead of "200 OK" (200 response is bigger as it contains the image).
    it's better than nothing but you still have 1 request + 1 response for nothing.
    Another problem is that you need SYS access to implement this, which is not possible on an hosted server. (note that for images from the file system it is already foreseen by apex 3.1, Tyler's note is for images from the db)
    2) if you preload the image (using myimage=new Image();myimage.src='...';), then there is max 1 request per browser session.
    There are 2 minor issues here:
    - no caching across sessions
    - if u don't want to preload all the images (example a page with lots of thumbnails, when user clicks it show a bigger image, in that case the thumbnails can be preloaded but overkill for the big images), then you need to load the image, wait until the image has loaded before displaying it, it does not slow down the execution, but requires some extra JS.
    I'm not asking anyone to investigate it, i can live with the 2 workarounds,
    but just in case someone encountered the same problem and already fixed it.
    Let me know if u managed to use the John Scott's technique with Firefox. (U can use Firebug to see the http traffic)
    Thx
    Tim

    Hi Anshul, hope these help. Let me know if you need to see anything else.
    Best,
    Menu Settings:
    Tab Hyperlink:
    Label Text with with hyper link option not available (works as a hyperlink in chrome and IE though):
    Thanks for the help in advance!

  • Mail attachment image caching problem with C7

    Using C7-00 and Mail for Exchange with up to date software. I received two Mobile Boarding Pass emails from Lufthansa for my flights. These emails contain barcode.gif as an attachment that one can show at the gate when boarding. Now the two emails contain attachment with same name (barcode.gif) and the images are equal in size too. The problem is that for the second mail the phone shows the attachment of the first email!
    I have read that Symbian^3 has for performance reasons aggressive image caching feature. But in this case this causes a real nasty bug!
     - Juha

    I have found a solution.
    In the IMG src tag we had been using /images/gfx/image.gif
    By changing this to /./images/gfx/image.gif the images are no longer cached and update immediately when changed.
    PQ

  • Increase still image cache when working only with images?

    I've been having hundreds of out of memory issues when working on a still image project. Thought it was solved but it hasnt.
    If im working totally with still images (Jpegs, Tiffs and PSD's) should I increase the Still Image cache from its default amount? I have scoured the internet trying to find out what the Still Image Cache is but cant find an explanation anywhere.
    I increased it this morning and all is well so far.....
    Might this solve my problem.

    The Still image cache is the amount of RAM assigned to the playback of the stills. That's what that slider adds... it should help to make it larger when you are working with a lot of stills. They are cached to RAM instead of being read from disk...
    From the manual:
    Still Cache: This specifies the amount of RAM used to hold still images for real-time playback. The still cache that is allocated is a percentage of the excess RAM allocated to Final Cut Pro, so adjusting the Application slider also adjusts the amount of RAM available to the still cache. The more RAM allocated to the still cache, the more still frames can be played back in real time in the currently selected sequence. If another sequence is opened, the contents of the still cache are replaced with stills from the new sequence. If there is no excess RAM available, this slider is dimmed.
    Jerry

  • Messages Opening Image Cache Folder when Sending Files

    Messages / iChat seems to be opening my image cache folder every time I send an image to my contacts the image cache folder opens in Finder and stays open with the copied image. Is there a way to get rid of this? It's really annoying. It started happening after I updated to Mavericks.
    Thanks!

    Hi,
    I don't have an answer for this one.
    Are you finding those items are zipped before Sending ?
    Where are they from?
    I get them zipped when sending a pic dragged from a Browser or from iPhoto but not from the Desktop or a Finder window.
    10:44 pm      Tuesday; November 5, 2013
      iMac 2.5Ghz 5i 2011 (Mavericks 10.9)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad

  • How to disable image cache in Mail 7

    I urgently need to disable the image cache in Mail 7. How can I do that?
    Reason: I regularly get mails with image files that are essential parts of customer orders. The image content is different in each mail, but the filename is the same.
    Mail 7 displays the same image in every mail until I restart it, it obviously displays a cached file instead of the original image.
    Where is the Mail-cache-file? Can I writeprotect it?

    I think Private Browsing might be what you are looking for,
    have a look here for more info
    [https://support.mozilla.com/en-US/kb/Private%20Browsing]
    also not sure how much access you have on a company workstaion to change settings in Firefox
    Hope this helps :-)

  • Mail attachment image caching problem

    Using C7-00 and Mail for Exchange with up to date software. I received two Mobile Boarding Pass emails from Lufthansa for my flights. These emails contain barcode.gif as an attachment that one can show at the gate when boarding. Now the two emails contain attachment with same name (barcode.gif) and the images are equal in size too. The problem is that for the second mail the phone shows the attachment of the first email!
    I have read that Symbian^3 has for performance reasons aggressive image caching feature. But in this case this causes a real nasty bug!
     - Juha

    I have found a solution.
    In the IMG src tag we had been using /images/gfx/image.gif
    By changing this to /./images/gfx/image.gif the images are no longer cached and update immediately when changed.
    PQ

  • Web template image cache

    goodmorning everybody,
    does anybody know where I can clear the image cache when running a web template.. It keeps displaying the old image even though I replaced the image with a new one in the mime repository...

    hi Joris,
    try
    - WAD menu tools -> setting -> delete cache -> delete cache
    - delete browser cache (Internet Explorer or other)
    and
    - SMICM->go to->HTTP server cache->invalidate->golbal in system
    or transaction rsrt -> cache monitor -> delete
    - transaction RSRCACHE
    oss note 456068
    Mime Repository Icons
    How to clear Cache in SAP BW
    hope this helps.

  • Image Caching

    Hi
    I'm trying to implement Image Caching on an Oracle XE database following Tyler Muth's blog post http://tylermuth.wordpress.com/tag/oracle-plsql-images-caching/
    Has anyone managed to implement this successfully?
    I've run the following as sys :
    begin
    DBMS_EPG.SET_DAD_ATTRIBUTE (
       dad_name    => 'APEX',
       attr_name   => 'cgi-environment-list',
       attr_value  => 'HTTP_IF_NONE_MATCH');
    DBMS_EPG.SET_DAD_ATTRIBUTE (
       dad_name    => 'APEX',
       attr_name   => 'cgi-environment-list',
       attr_value  => 'IF_MODIFIED_SINCE');
    end;
    /And my function to download the images includes the following:
        v_etag_head := owa_util.get_cgi_env('HTTP_IF_NONE_MATCH');
        v_etag_str := lpad(p_file_id,2,0)||to_char(v_date_last_modified,'DDMMYYYYHH24MISS');
        if v_etag_head = v_etag_str then
          owa_util.status_line(
          NSTATUS         => 304,
          CREASON         => 'Not Modified',
          BCLOSE_HEADER   => true);
          return;
        else
          owa_util.mime_header(v_mimetype, FALSE );
          htp.p('Date: ' ||to_char(sysdate,'Dy, DD Mon RRRR hh24:mi:ss')||' GMT');
          htp.p('Content-length: '||v_file_length);
          htp.p('Content-Disposition: inline; filename="'||v_filename||'"');
          htp.p('Last-Modified: '||to_char(v_date_last_modified,'Dy, DD Mon RRRR hh24:mi:ss')||' GMT');
          htp.p('ETag: '||v_etag_str);
          htp.p('Expires: ' ||to_char(sysdate+(1/12),'Dy, DD Mon RRRR hh24:mi:ss')||' GMT');
          htp.p('Cache-Control: max-age=300');
          owa_util.http_header_close;
          wpg_docload.download_file(v_blob);
       end if;However, owa_util.get_cgi_env('HTTP_IF_NONE_MATCH') always returns null. I've checked using LiveHTTPHeaders and the If-None-Modified is being sent. This is running on a local Oracle XE database (using the EPG), running APEX 4.0.0.00.46 and Windows 7.
    I've searched the forum and there are four other posts that refer to HTTP_IF_NONE_MATCH, however these haven't helped. If anyone has any ideas or needs any more information, please let me know. And if you have got this working I'd love to know how, even just so I know it's possible!!
    Thanks for any help.
    Sara

    Bump.
    Has anyone managed to implement this successfully? Is there anything I can check? Or is this a bug with the EPG?
    This is causing us massive problems and I can't see what I've done wrong. Any help is really appreciated.
    Thanks
    Sara

  • Image Caching issues

    I have a question regarding image caches in Safari. Why is it that when I change an image that is on my website, the changes do not show. I'll upload an image with the same name as the previous one and when I go to the browser and refresh the old image is still there. I've tried to refresh, empty cache, and reset safari. I've also done shift+refresh, option+refresh, etc. When i view the page on a pc the changes are made and if they don't show automatically I just use a shift+refresh on the pc and it works. I've also had the same problem with pdfs.
    Has anyone had this problem and if so do you know if there is anything to be done about this?

    Hi Scott,
    I had the same with my website an I did the following ...
    * Trash the whole Safari cache folder ... empty trash
    Go to: Home>UserName>Library>Chashes>Safari
    By the way to 'reload Safari' it is command-R
    Dimaxum

  • HTML Image cache

    I need to clear the html image cache that mail uses. I get a newsletter with a header image but always see the old image if they have updated it.
    How can I fix this ?
    TIA

    Ok, I found out how to do it, not sure if it will cause any other issues but you have to delete this file
    User/library/caches/com.apple.mail/Cache.db

  • How to get blob image width with ordimage?

    Hello,
    I have trouble getting image width with ordimage. I have quite the same program for processing images as here: http://spendolini.blogspot.com/2005/10/manipulating-images-with-database.html
    so I have declared image files as BLOB files. How can I get the width for the them?
    There is a sample from ordimage reference:
    DECLARE
    image ORDSYS.ORDImage;
    width INTEGER;
    BEGIN
    SELECT p.product_photo INTO image FROM pm.online_media p
    WHERE p.product_id = 3515;
    -- Get the image width:
    width := image.getWidth();
    DBMS_OUTPUT.PUT_LINE('Width is ' || width);
    COMMIT;
    END;
    the ORDSYS.ORDIMAGE is used instead of BLOB here. when i do the same then i can't select BLOB content into the ORDSYS.ORDIMAGE variable. And otherwise I can't use the getWidth with the BLOB variable.
    Can anybody help please?

    Hi,
    the column blob_content is not suitable for storing into v_image2 because variable v_image2 is of type ORDSYS.ORDIMAGE and the column is BLOB.
    I used the following method instead:
    declare
    image blob;
    attributes clob;
    img_mimeType varchar2(32);
    img_width integer;
    img_height integer;
    img_contentLength integer;
    fileFormat varchar2(32);
    contentFormat varchar2(32);
    compressionFormat varchar2(32);
    begin
    DBMS_LOB.CREATETEMPORARY(attributes, TRUE, DBMS_LOB.CALL);
    select img
    into image
    from image_repository
    where id = 0;
    ORDSYS.ORDImage.getProperties(image,
    attributes,
    img_mimeType,
    img_width,
    img_height,
    fileFormat,
    compressionFormat,
    contentFormat,
    img_contentLength);
    dbms_output.put_line(img_mimeType);
    dbms_output.put_line(img_width);
    dbms_output.put_line(img_height);
    dbms_output.put_line(fileFormat);
    dbms_output.put_line(compressionFormat);
    dbms_output.put_line(contentFormat);
    dbms_output.put_line(img_contentLength);
    DBMS_LOB.FREETEMPORARY(attributes);
    end;
    try adapting this code and think about the possibility of "caching" image properties, because it takes some time to retrieve them every time.
    Bye,
    Flavio
    http://oraclequirks.blogspot.com/search/label/Apex

  • JE as Image Cache

    Folks,
    We're considering using JE as an image cache for a large(ish) number of small(ish) images. The question is whether or not JE would be fit for this particular use. The requirements are simple: store a single Java object via DPL in the form:
    class Image{
    @PrimaryIndex
    String uuid;
    @SecondaryIndex(...)
    Date lastModified;
    @SecondaryIndex(...)
    Date expires;
    byte[] data;
    We expect to store 50K or so images with data[] sizes ranging from 1k to 50k. Any reasons why JE might not be a fit? We've stored blocks of XML in the past without issue, so don't expect issues here.
    Regards,
    -tyson

    Tyson,
    You're probably familiar with this already, but JE is agnostic about data types at the actual storage level. Only the DPL layer understands what type the data is. So in this case, the major factor to consider is the size of the data.
    We have certainly heard of uses cases with data in the 1 - 50K range, and it should be possible, but I'll explain the factors to consider in terms of the size of the data.
    1. Because of JE's append only storage architecture, an update to a record is a new, fully size copy of the record. So if a large data record is updated a lot, the log does grow. Of course, those older versions are obsolete, and the log cleaner removes them, but it results in log file growth and compression (cleaning) in larger degrees of granularity.
    2. In general, JE pulls data records in their entirety into cache. So a large data record takes more room, the cache fits fewer data records, and there may be more eviction activity going on to maintain the cache. One exception is the "Partial" option when fetching data entries, described in the Cursor javadoc under "Using Partial DatabaseEntry Parameters" here: http://www.oracle.com/technology/documentation/berkeley-db/je/java/com/sleepycat/je/Cursor.html. It lets you fetch only the key portion of a data record and avoid pulling the data portion into the cache, when using READ_UNCOMMMITED, and can be useful in some cases.
    3. We don't yet provide any streaming APIs, which would be handy for really large records.
    That's what I can think of! Maybe folks who have been storing large records can speak to their experience. But we do know that people do store records that large in JE.
    Regards,
    Linda

  • Cacheasbitmap and filters - filtered image cached?

    cacheasbitmap and filters - filtered image cached?
    When filter is applied to component, it has cacheAsbitmap assigned to true automatically. Hovewer, does it cache filtered result?
    Does I need to enable cacheAsBitmap on parent?
    In need filtered representation to be cached and filter not reallplied on every parent redraw.
    Does cacheasbitmap works fine on parent if children extend beyond parent group with explicitly specified size?
    Does cacheasbitmap works fine on parent if children has BlurFilter applied with large radius which extend child pixels beyond parent explicitly specified size?

    cacheasbitmap and filters - filtered image cached?
    yes, the filtered bitmap is cached.
    Does I need to enable cacheAsBitmap on parent?
    no, you don't need to enable cacheAsBitmap on the parent for the above to occur.
    In need filtered representation to be cached and filter not reallplied on every parent redraw
    if there's any bitmap change (including a bitmap change to the parent) to the filtered component, it will be recached.
    Does cacheasbitmap works fine on parent if children extend beyond parent group with explicitly specified size?
    yes
    Does cacheasbitmap works fine on parent if children has BlurFilter applied with large radius which extend child pixels beyond parent explicitly specified size?
    child pixels can't extend beyond the parent because the parent changes size depending on the size of its children (as well as its own graphics).

  • Photoshop-When opening image without tab view, image opens with only a portion in view

    I having an issue with CC.
    When electing in the preferences to not open image in Tabs. The images open with only about 25% of the image area showing. Forcing me to (command) 0 for full to screen preview or (command) +/- to see the image.
    I am not talking about seeing the image at 100% resolution just the entire image within the floating window without having to command before view.
    Sidenote: Adobe Customer Service is all based in India. I spent 4 hours on the phone only to hear that this is that way photoshop works.
    There would be no logical explanation for this. Since the first version of Photoshop this has not been the case.
    I think this should be called view porn with wife in the room mode. Other than that I see no point.
    Can anyone help?
    Lv
    Chadwick Tyler

    Moving discussion to Photoshop forum.

Maybe you are looking for

  • External display resolution

    I have Dell up2414q monitor which is capable of displaying up to 3840 x 2160. But when I connect my 11-inch Macbook Air (the latest 2014 model), which is capable of 2560 x 1600, shows only 1920 x 1080. This is the highest resolution listed in display

  • What's wrong with my iPod shuffle? any ideas?

    I received my iPod shuffle the other day, and have installed the software and started moving songs from my computer to the iPod. When the iPod is in my computer, the songs all show, but when I take it out, the iPod will not play... is this a fault wi

  • Recordset Navigation in Dreamweaver8

    Dreamweaver8 has changed the way recordsets are created from the ADODB.Recordset method to the ADODB.Command method. This seems by default to create a recordset with a forward only moving cursor. I would like to be able to move backwards and forwards

  • Top 10 Ranking

    I used a procedure to calculate fields in a report and i want to select the top 10, or 20 or 100 from the list the pocedure generated, how can i achieve this. The user will supply the ranking. If the user puts 10 the top 10 cuatomers will be displace

  • Popup menus in Forms 10g and Java Bean

    Hi all. What class in Java corresponds with popup menus(not in menu module) ? I know that oracle.ewt.lwAWT.lwMenu.LWPopupMenu is corresponds with MenuBar's submenu. I can find Buttons, Text Fields, Menu and other components in my Form-Applet, but I d