Memory sensitive cache? (Clearing Softreference only when necessary)

I have a number of objects that I load into memory from files. These are large objects, and I cannot have all of them in memory at the same time. However, because they take time to load, I would like to load them in as seldom as possible. SoftReferences seemed to be an ideal way to do this, except that the objects pointed to by my SoftReferences are being finalized long before I run out of available memory.
Is there a way to have these references hang around as long as possible? Ideally, they'd only clear if an OutOfMemory error is about to be thrown.
Mark McKay

Well, I am having the exact same issue -- and only one month after you are. I have objects, loaded slowly from xml files, which i cache in memory. Typically there will only be dozens or hundreds of them, but sometimes there will be thousands or tens of thousands, and I would like to improve my cache (which is currently just a Hashtable and a wrapper) to be contextually memory-sensitive.
I'm confused as to the difference between a SoftReference and a WeakReference, especially since it seems to me that a SoftReference is the way to go but, as I look around the web for advice, most people seem to prefer WeakReferences. Since I'm leaning toward SoftReferences, I guess I don't want to use a WeakHashMap, rather I want a SoftRefHashtable of some kind, which perhaps I will have to implement.
If I roll my own, is it as simple as overriding get() and put() to wrap the parameters in SoftReferences, and unwrap them back into objects?

Similar Messages

  • Being specific in the Constructor, only when necessary

    Hello! I am new to Java. I have a few really simple question. I know this much so far:
    - Hiding is when a variable overrides another within a stronger (more inner) scope.
    - Hiding is not good convention since it may confuse readers of code.
    So I have this example. It's only part of an example, so it will only be the essential parts:
    package example;
    import java.awt.*;
    public class Application {
         * The options component for this Application.
        Component optWindow;
        public Application() {
            Window optWindow = new OptionWindow();
            optWindow.pack();
            this.optWindow = optWindow;
        public void showOptions() {
            optWindow.setVisible(true);
        @Override protected void finalize() throws Throwable {
            optWindow.setVisible(false);
            optWindow = null;
            super.finalize();
    class OptionWindow extends Frame {
        public OptionWindow() {
            super("Options:");
    }Anyway, I also know that optWindow in the constructor hides this.optWindow. But I'm not sure 100% why.
    My reasoning behind wanting to do this is that I don't think that the rest of the Application needs to know that optWindow is a Window other than in the constructor, so the Application Object should store it as just an abstract component. A sort of "type encapsulation and subclass separation".
    I believe that the reason why this is hiding is because optWindow refers to the "reference" of the OptionWindow object, not the object itself =) I understand that so far.
    But I believe it shouldn't because the this.optWindow does not refer to anything until after the constructor, so it shouldn't be hidden.
    I have a few solutions I know of:
    1) Drop the idea of storing optWindow as a Component in the Application Objects. Just store it as a window everywhere.
    2) Keep it this way anyway.
    3) Use a different variable name for the optWindow in the constructor.
    There are in the order that I'd rather do them in. I understand that option 1 is the best. Option 2 might potentially be okay. Option 3, I really do not like since it's giving two names or references to the same object and it would be annoying to come up with a new name for it. But I could come up with something simple like "window" if necessary inside of the constructor.
    My questions would be:
    1) Is this a good idea to make the window an abstract component outside of the constructor?
    2) Is this a "good" use of hiding; or does the rule always apply to avoid hiding?
    If Question 1 is true, I'd probably go with Option 1. If Question 1 is false, but Question 2 is true, I'll go with Option 2. If Question 1 is still false, but so is Question 2, I'll go with Option 3.
    Thank you very much in advanced! I really appreciate the help! =) And I look forward to asking more questions.
    Edit: I wrote that OptionWindow throw Frame instead of "extends Frame".
    Edited by: Macleod789 on Mar 30, 2010 2:24 PM

    Macleod789 wrote:
    Hello! I am new to Java. I have a few really simple question. I know this much so far:
    - Hiding is when a variable overrides another within a stronger (more inner) scope.
    - Hiding is not good convention since it may confuse readers of code.It's common and perfectly acceptable in some situations. Constructors and setters come to mind. If your code is well-written, it won't be at all confusing.
    >
    So I have this example. It's only part of an example, so it will only be the essential parts:
    package example;
    import java.awt.*;
    public class Application {
    * The options component for this Application.
    Component optWindow;
    public Application() {
    Window optWindow = new OptionWindow();
    optWindow.pack();
    this.optWindow = optWindow;
    public void showOptions() {
    optWindow.setVisible(true);
    @Override protected void finalize() throws Throwable {
    optWindow.setVisible(false);
    optWindow = null;
    super.finalize();
    class OptionWindow extends Frame {
    public OptionWindow() {
    super("Options:");
    }Anyway, I also know that optWindow in the constructor hides this.optWindow. But I'm not sure 100% why.Because the JLS defines that it does. Local variables always hide members of the same name. That's the rule the designers decided on.
    My reasoning behind wanting to do this is that I don't think that the rest of the Application needs to know that optWindow is a Window other than in the constructor, so the Application Object should store it as just an abstract component. A sort of "type encapsulation and subclass separation".\Huh? Reason behind doing what? Declaring the optWindow member as a Component rather than a Window? Well, yeah, if the rest of the Application class only cares that it's a Component and could do its job the same way if any other Component were used, then you're right--declaring it as a Component is the correct approach. But then it should not be named optWindow. And if the rest of the Application class doesn't need it to be a Window, then the c'tor has no reason to require that either.
    I believe that the reason why this is hiding is because optWindow refers to the "reference" of the OptionWindow object, not the object itself =) I understand that so far.Reference vs. object is an important distinction to understand. However, it has nothing to do with hiding. Hiding is just about identifier names, like variables. The fact that their values are references is irrelevant to the hiding rules.
    But I believe it shouldn't because the this.optWindow does not refer to anything until after the constructor, so it shouldn't be hidden.Show me the part of the JLS that says that hiding has do with whether the variable in question has been assigned or not.
    In some scopes, two distinct identifiers with the same name can exist. There has to be some rule about which one takes precedence when there's no qualification. It's simpler if it's consistent and it's always the local. If it weren't, then a) it would be inconsistent, which would be confusing, and b) we'd need a new keyword or other mechanism to explicitly indicate that we're talking about the local. Or else we simply wouldn't be able to access the local variable in those contexts, which would be pretty stupid, I'm sure you agree.
    I have a few solutions I know of:Solutions to what? What's the problem you're encountering?
    1) Drop the idea of storing optWindow as a Component in the Application Objects. Just store it as a window everywhere.I addressed that above, and it has nothing to do with hiding.
    2) Keep it this way anyway.So, a "solution" to whatever problem you're having is to do nothing and just keep having the "problem"?
    1) Is this a good idea to make the window an abstract component outside of the constructor?If it's Component in the member variable, it should be in the c'tor too. If the c'tor requires a Window, then it must be because the member has to be a Window.
    2) Is this a "good" use of hiding; or does the rule always apply to avoid hiding?It's very common and acceptable to have parameter names match member names where the parameter is being used to set the member.
    Edited by: jverd on Mar 30, 2010 2:49 PM
    Edited by: jverd on Mar 30, 2010 2:50 PM

  • Ask user filesystem access permission only when necessary

    Hello
    Sorry I can't find an explicit title.
    I try to remove my applet signature to avoid the startup security dialog which is not user-friendly.
    But my applet offers the possiblity to save something on the user file system that can't be done without signed applet.
    Is there a way to ask the file system access permission just when it is mandatory, like the PrintUtilities.print() does?
    Thanks you in advance

    Hi ,
    Thanks for you reply.
    I will try this out and will let you know the results.
    Are you talking about "setting default home page" for the user ,in your last line of reply ?
    I think , this is the case when user clicks on Home link then this default page will be rendered. Am i right ?
    Is there any docs which can tell all about the Access Privileges and also tells about how to play with Role Based Security in Oracle Portal Server ?
    Thanks Again
    <Neeraj Sidhaye/>
    Try_Catch_Finally AT YAHOO DOT COM
    http://ExtremePortal.blog.co.uk

  • Printing in Black only when necessary-then color

    I had  HP 9800 software installed by HP for my HP Officejet 4600 series printer . I would like to print text in black only. How do I do this?
    This question was solved.
    View Solution.

    No problem and great to hear.
    Could you please click "Accept as Solution" if you feel my post solved your issue, it will help others find the solution. Click the "kudos thumbs up" on the left to say thanks for helping! Thank you.
    I worked on behalf of HP.

  • Download jar only when it is used

    Hello,
    I have an applet that uses some jar files, is it possible download the jar file only when it is called by the applet?
    Thanks,
    Pati

    If you add an index file in the first jar file on the
    applet's class path, the Java Plug-in downloads jar
    file only when necessary.
    You can find more information at:
    http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#JAR%20Index
    Regards

  • Web ADI works only when cache is cleared

    I have created a custom integrator and the web ADI component works only when I clear the cache from the functional administrator responsibility in Oracle Apps. The component has a lot of validations for the fields and is expected to insert upto 2000 lines, It works fines for a small number of lines but the web ADI hangs for a large number of lines (>500). But if I clear the cache, it works fine. Anyone has a solution for this, cause I cant clear the cache always and I cant tell my customer to do the same.
    G. Arun
    Oracle SSI

    The WebADI caching can be very confusing. I made a little summary of what you can do to avoid caching problems like:
    "ORA-06508: PL/SQL: Could not Find Program Unit being Called in Custom Web ADI" or
    "SQL exception occurred during PL/SQL upload"
    A) clear cache with http://<machine>:<port>/OA_HTML/BneAdminServlet
    B) clear IE cache & restart
    C) clear the cache from the functional administrator responsibility
    D) Bounce the Apache server
    E) SQL command: Alter system flush shared_pool
    F) Download another WebADI spreadsheet (but you can re-use your old spreadsheet)
    G) log out and log back in EBS
    H) login at another computer and try it there
    ...or sometimes just wait for a while till it works again.
    Jeroen

  • Acmcneill1ug 14, 2014 7:16 AM I have IMac OSX 10.9.4, 4GB,Processor 3.06 with Intell2Duo. I would like to check for Malware. I run a TechTool Pro 6 every month and that comes up great. When check how much memory I am using, with only Safar

    Acmcneill1ug 14, 2014 7:16 AM
    I have IMac OSX 10.9.4, 4GB,Processor 3.06 with Intell2Duo. I would like to check for Malware. I run a TechTool Pro 6 every month and that comes up great.
    When check how much memory I am using, with only Safari open I am using 3.9 and more of her 4.0 memory. She is very. very slow in processing. I had 4000
    trash to clean out and it took her over an hour to expel. Also for some reason Safari will not allow me to click on a link, in my G-mail, and let it go to the page.
    It has a sign saying a pop-up blocker is on and will not let me do it. I must open the stamp to look at my e-mails and if I have redirected link now I can do it.
    I have not changed my preferences so where is this pop-up blocker?
    I have looked at preferences on Safari and Google, which I do not understand Google, and do not see where this blocker could be.
    Malware is something I want to make sure is not on my computer. Tech Tool Pro 6 is all I know of and it does not detect Malware.
    Help.
    Ceil

    Try Thomas Reed's Adware removal tool. He posts extensively in the communities.
    Malware Guide - Adware
    Malware Discussion

  • Clear IDOC creation when only header level changes are made ME22N.

    Hi All,
    when the PO is  on changed in the header level only(for example header texts and header code)  and when we execute RSNAST00 one BADI getts triggered which checks if the Item category is 9 and  badi will clear the IDOC creation.
      If the PO item category is = 9, the IDOC must not be created. This badi works fine if the changes are made at
    1)at Item level
    2)both header level and Item level
    In case of 1 and 2 we have both header segment E1EDK01 and item segments E1EDP01.As a result it checks for the item category in the item segment.so idoc is not created.
    3)BADI is not working when the changes are made at the header level only. The IDOC is getting created even though the PO has the item category as 9.
    I found in this case only header segments are availble while debugging and the item segments are not there to check the condition for the item category.
    Please any one can suggest me possible solutions to  clear idoc creation when only header level changes are made ME22N.
    The BADI used is as below.
      DATA : lwa_data TYPE edidd.
      DATA : lw_dp01 TYPE e1edp01.
      DATA : lwa_control TYPE edidc.
      CHECK idoc_control-rcvprn = '3PL' AND idoc_control-idoctp = 'ORDERS05'.
      LOOP AT idoc_data INTO lwa_data.
        IF lwa_data-segnam = 'E1EDP01'.
          lw_dp01 = lwa_data-sdata.
          IF lw_dp01-pstyp = '9'.
            CLEAR create_idoc.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDMETHO
    Thanks in advance.

    Hi all,
    Is there  any way that I can get the item category details when Only header level changes are made to the PO in ME22N and only header segments are available in the IDOC.
    Is this possible:- Fetch the po number and item category details from ekpo table that matches with  the header segment po number and then check for item category value  to clear the idoc creation?
    Any information is helpfull.
    Edited by: Selina.selk on Nov 20, 2009 1:39 PM
    Edited by: Selina.selk on Nov 20, 2009 2:49 PM

  • HT4689 My daughters Macbook Pro memory appears to be full.  When she puts it on it only stays on the "purple" screen how can I get on it to create memory?

    My daughters Macbook Pro memory appears to be full.  When she switches it on it stays on the "purple" screen.  How do I get to go further to clear some memory?
    Thanks
    Marlene

    Try these tips.
    1. Start up in Safe Mode.
        http://support.apple.com/kb/PH11212
    2. Empty Trash.
        http://support.apple.com/kb/PH10677
    3. Delete "Recovered Messages", if any.
        Hold the option key down and click "Go" menu in the Finder menu bar.
        Select "Library" from the dropdown.
        Library > Mail > V2 > Mailboxes
        Delete "Recovered Messages", if any.
        Empty Trash. Restart.
    4. Repair Disk
        Steps 1 through 7
        http://support.apple.com/kb/PH5836

  • Amazon website does not load properly. Text only. Using Windows XP. Cache clearing does not work.

    The amazon.com website will only load text, although it does load an occasional image. I am using windows xp, firefox version 8.0

    See High contrast schemes:
    * http://www.microsoft.com/enable/products/windowsxp/default.aspx
    Reload web page(s) and bypass the cache.
    *Press and hold Shift and left-click the Reload button.
    *Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Linux)
    *Press "Cmd + Shift + R" (MAC)
    Clear the cache and the cookies from sites that cause problems.
    "Clear the Cache":
    *Tools > Options > Advanced > Network > Offline Storage (Cache): "Clear Now"
    "Remove Cookies" from sites causing problems:
    *Tools > Options > Privacy > Cookies: "Show Cookies"
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    *Don't make any changes on the Safe mode start window.
    *https://support.mozilla.org/kb/Safe+Mode

  • Photoshop CS5 interface gets really slow *only* when an image is open

    So this is really odd. Photoshop gets really slow when any image, regardless of size is open. When there are no images open it runs smoothly. The interface gets really laggy, filter usage, tool selection or any other usage is really sluggish, but only with an image open, even if it's a single pixel.
    I've tried different performance settings - changing where the scatch drive is, how much memory to allocate, what the cache levels are set at, enabling/disabling openGL, etc. It makes no difference if it's after a fresh reboot or if it's been on for days. No software has changed since the upgrade. Memory test don't show any issues and no other application has this problem - Illustrator, After Effects, Maya, Mudbox, etc. are all fine.
    My system specs
    Windows 7 x64 Enterprise - Service pack 1 installed
    Dual Xeon quadcore E5620 @ 2.4GHx (sixteen threads w/hyperthreading)
    96 GB Ram - DDR3 - 1333 MHz / PC3-10600 - registered - ECC
    Nvidia Quadro FX 3800 - with latest stable performance drivers v 295.73 (tried changing these, no affect)
    Western Digital VelociRaptor  150GB 10000 RPM 16MB Cache SATA 3.0Gb/s OS Drive
    X3  Seagate Constellation 2TB 7200 RPM SAS 6Gb/s setup in a RAID 5 config
    I'd think it would be a memory issue if all apps had similar problems, or if PS had issues when just being open. It's odd that it happens only when an image is open.
    Thanks for any an all help.
    Duncan

    Duncan York wrote:
    I've tried different ..., enabling/disabling openGL,
    Just to make sure, did you close and restart Photoshop after changing OpenGL settings and before testing?  That's important, and not having done so could lead you to invalid assumptions.
    -Noel

  • Why is my cache clearing? I get low PLE

    Monitoring the system today returned the following:
    In our production server we have 32GB of RAM
    SQL uses 26-27GB
    6 GB (static) of that are "stolen" – used for other stuff that are not database caching or managing.
    0.5GB (static) are used for locking.
    All night long the free memory was just below 2GB and that is good. It means we have enough memory for all databases.
    At 7:45 AM the free memory grew to 10GB and at 8:00 to 16GB. We don’t need this memory free, we need it for cache.
    The cache that was all night at 20GB dropped to 11 GB and during the day varied to the lowest level of 4GB.
    The bright green line is our goal, "Page Life expectancy". With hour memory it should be days,
    but it is now averaging about a minute and a half!
    Free memory is not a need of the system so it is strange the cache is being depleted by it.
    sould I sample data in a higher rate, maybe something else is stealing the cache and returning free memory very quickly.
    what could be the issue?

    Thanks Shanky,
    here are the results:
    Memory_usedby_Sqlserver_MB Locked_pages_used_Sqlserver_MB Total_VAS_in_MB      process_physical_memory_low process_virtual_memory_low
    26904                      0                             
    8388607              0                           0
    Microsoft SQL Server 2012 (SP1) - 11.0.3153.0 (X64)
    Jul 22 2014 15:26:36
    Copyright (c) Microsoft Corporation
    Standard Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
    It is dedicated to data only (no ssis,ssrs,ssas)
    One instance.
    max memory 27GB
    Should  I change minimum memory from 0 to 20GB?
    I can cause real memory preasure by reading all transactions. I even managed to produce:
    An error occurred while executing batch. Error message is: Exception of type 'System.OutOfMemoryException' was thrown.
    But not here is my problem. My issue is when there is pleanty free memory and cache gradually reduces.

  • Cache clearing during high planning usage

    Hi
    I was going through some performance notes for Integrated Planning and one of the suggestions there was Cache clearing during high planning usage.
    What does this mean and how can it be performed
    Thanks
    Rashmi.

    Hi Rashmi,
    what is the note you mentioned?
    The OLAP cache usually is a mechanism to improve performace, though there might be case where the 'administration' of the cache creates some extra costs that may lead to better results without using the cache. But there are no general guidelines when this might happen. This heavily depends on the data model, queries and data access pattern.
    In planning - as explained in note 1056259 - caching might be used via the planbuffer queries. These are system generated queries involved when input ready queries read transaction data. The query name is CUBE/!!1CUBE (aggregation level on an InfoCube) or MPRO/!!1MPRO (aggregation leve on a multiprovider). Via RSRCACHE (or also via RSRT, button 'Cache Monitor') you can check the caches. Via RSRT you can also deactivate the cache for a query or planbuffer query. You may play with these settings.
    Caching is working best if the same data are shared for different users. But in planning different users sharing overlapping data in change mode will lock each other. So one might share actual data. One also might try to do a cache 'warm up' using a filter that creates caches that can be reused by different users. This would mean that plan users have non-overlapping selections but the warm up would be done before with a union of some of the filters used by the plan users. But how to do this in detail and whether it is worth the effort can only be answered in the customer project.
    Regards,
    Gregor

  • Is there a way to play an mp4 file at the beginning of a published project only when the project is accessed from a specific site?

    Is there a way to play an mp4 file at the beginning of a published project only when the project is accessed from a specific site?
    A little background info. I use Captivate 7 and currently have over 100 projects that I maintain on a quarterly basis. I publish using the SWF format and upload the swf/htm files to a server where they are then accessed from a few locations (within our online documentation, in our software product, on two different websites). Many of the projects are linked so some will be viewed as a series and others viewed as a standalone video. Each video uses the same template and includes an intro and end slide. Now my organization wants to implement a new intro to all videos (those I publish and those from several groups across the organization). My current intros provide overview material for the specific video so the new intro, which is an animation with audio in mp4 format, would need to be placed at the start of each project. The issue is, the intro adds 9 seconds to every video and in many cases doesn’t add any value (say, if a user accesses the video from within our product or views the videos as a series). I’ve talked it over with my boss and we want to try to add the intro only to videos accessed from site X, not any other location. So now to my question. Is there a way to play an external mp4 file (intro) only when the published project is accessed from a specific site, therefore eliminating the need to update each project? Maybe there's a way to add a parameter or variable to the URL or the html code?
    Thanks in advance for your suggestions. Please let me know if you need additional information.

    AimeeLove,
    I have a solution for you.  You may have to modify the code a little bit based on how long the timeline animation is for your clock.  I based mine on 3 seconds to complete a minute hand sweep around the clock.
    Milliseconds for each point on the clock:
    12 = 0
    1 = 250
    2 = 500
    3 = 750
    4 = 1000
    5 = 1250
    6 = 1500
    7 = 1750
    8 = 2000
    9 = 2250
    10 = 2500
    11 = 2750
    In the mouseover section for 12 o' clock, put this code...
    myVar = setInterval(function(){
         var pos = sym.getPosition();
         if (pos > 0 && pos < 50){
              sym.stop(0);
              clearInterval(myVar);
    },10);
    When you point to the time, the setInterval method loops every 100th of a second and checks the current position of the timeline.  When the timeline reaches the range between 0 and 50 milliseconds (almost impossible to hit 1 specific point), the timeline will stop at 0.  Also, the clearInterval will be fired to stop the loop.
    In the mouseout section, put this...
    sym.play();
    clearInterval(myVar);
    It start the clock again, and it also clears the loop in case you mouseout before you reach the range.
    Make sure that myVar is a global variable so you can clear it from the mouseout section.
    Repeat this for each point on the clock.  To avoid potential conflicts, you may want to use my12, my1, my2, etc. instead of myVar.  I put the milliseconds at the top that you would use as the beginning of the range.  50 milliseconds should be enough to catch it.  So, for 5 o' clock, you would make your range between 1250 and 1300.
    Let me know if you have any questions.  Thanks!
    Fred

  • I have one random Apple ID that appears only when I go to itunes or App Store.  For everything else I have my Apple ID and password all set.  Can I get rid of this thing?

    This is a Question:  I have one random Apple ID that comes up only when I'm trying to access Apps or iTunes.  I have another Apple ID with a password that works just fine for everything else.  I do not have a password for this random id.  How can I get rid of it?  I can't perform updates is the big issue.

    Jonathan:This seems to make a lot of sense.  My only follow up question is:  will I have any trouble getting iTunes and
    Apps back?
    Will apple charge me?  I really can't remember clearly, but it seems to me that iTunes and Apps were present on the
    iPad2 that was given to me as a gift, but I could be mistaken.
    If I am all clear for getting those two stores back with an easy selection, then I will use your solution.
    Have a great season, my friend- this was driving me nuts!  Thank you so much!
    Dianep

Maybe you are looking for

  • How to retrieve data from a removed hard drive????

    I had an iBook G3 12" when the logic board broke. I dismantled the computer and sold all the parts. I kept the hard drive hoping that I could retrieve the data. Is there a product that will connect the hard drive to a WINDOWS based computer and allow

  • Error message when creating a Master File

    I have finished editing a multicam clip of a graduation ceremony which is an hour and 27 minutes long. Clients are anxiously awaiting the DVDs/BR discs. There are six "Rotation" and one "Ribbon" titles and 21 chapter markers in the timeline. None of

  • After Windows XP reinstall....

    I tried searching the forum but merely became more confused! I have a 30gig ipod (purchased around dec '04)which is currently full of songs and play lists. After formatting my pc I am unaware of how to restore the song files (including purchased song

  • Help! Pls! Product Code Countries

    Hi Everyone, I asked once but I couldn't get any help, perhaps my phrasing was unclear and too complicated. The N86 (RM-484), Product Code: 0580867 (Europe Mea seap), corresponds to which country?Are English, French and Italian natively preinstalled

  • Soap -- xi -- jdbc

    Hi, I want build this scenary. I review the blog's and appear that the correct form to invoke the ws in XI is: <a href="http://host:port/XISOAPAdapter/MessageServlet?channel=<party>:<service>:<channel>">http://host:port/XISOAPAdapter/MessageServlet?c