SoftReference and WeakReference clearing

According to the javadoc of SoftReference:
http://java.sun.com/javase/6/docs/api/java/lang/ref/SoftReference.html:
Suppose that the garbage collector determines at a certain point in time that an object is softly reachable. At that time it may choose to clear atomically all soft references to that object and all soft references to any other softly-reachable objects from which that object is reachable through a chain of strong references.So all SoftReferences will be cleared atomically. Will WeakReferences be cleared at the same time atomically with the clearing of the SoftReferences?
In other words, is it possible that WeakReference.get can return a hard reference after the soft reference has been cleared by the garbage collector?
Cheers,
Dave.

Here is my test application which shows it works the way I was expecting, both references get cleared at the same time:
a_garbage_b_not: 0
b_garbage_a_not: 0
both_garbage: 2000However, I'm not sure this is conclusive enough and would please like confirmation and/or a link to some garbage collection documentation that states this is how it works.
public class Main {
    public static void main(String[] args) {
        int a_garbage_b_not = 0;
        int b_garbage_a_not = 0;
        int both_garbage = 0;
        int idx = 0;
        while (idx < 1000000)
            int jdx = 0;
            while (jdx++ < 100)
                idx++;
                ObjectA obj_a = new ObjectA(new ObjectB());
                WeakReference weak_a = new WeakReference(obj_a);
                WeakReference weak_b = new WeakReference(obj_a.obj_b);
                obj_a = null;
                boolean a_garbaged = false;
                boolean b_garbaged = false;
                int loop = 0;
                ArrayList rubbish = new ArrayList();
                while (!a_garbaged && !b_garbaged)
                    rubbish.add(new Object());
                    loop++;
                    a_garbaged = weak_a.get() == null;
                    b_garbaged = weak_b.get() == null;
                rubbish = null;
                if (a_garbaged && b_garbaged) {
                    System.out.println(idx + ": both_garbage, loops: " + loop);
                    both_garbage++;
                else if (a_garbaged && !b_garbaged) {
                    System.out.println(idx + ": a_garbage_b_not, loops: " + loop);
                    a_garbage_b_not++;
                else if (!a_garbaged && b_garbaged) {
                    System.out.println(idx + ": b_garbage_a_not, loops: " + loop);
                    b_garbage_a_not++;
            System.out.println("a_garbage_b_not: " + a_garbage_b_not);
            System.out.println("b_garbage_a_not: " + b_garbage_a_not);
            System.out.println("both_garbage:    " + both_garbage);
    private static class ObjectA
        private final ObjectB obj_b;
        private ObjectA(ObjectB obj_b)
            this.obj_b = obj_b;
    private static class ObjectB
}Cheers,
Dave.

Similar Messages

  • How does "SoftReference" and "WeakReference" work?

    Hello, everybody!
    I want to design a cache with "SoftReference"
    the cache is just like:
    int length = 1024;
    Object[] cacheObjects = new Object[length+1];
    cacheObjects[value.hashCode() & length] = new SoftReference(value);I hope the "value" and soft reference are cleared by gc at some time before throwing "OutOfMemoryError" if there is no directly reference to the "value" object.
    So I wrote a simple test:
    private static void softCache() {
            int i = 400000;
            List<String> list = new ArrayList<String>(i + 1);
            String a = "...."; // a huge string;
            while (i-- > 0) {
                list.add(a + i);
            Reference<Object> ref = new SoftReference<Object>(110);
            try {
                long[] b = new long[20000000];
                System.out.println(b[0]);
            } catch (Exception e) {
            } finally {
                System.out.println(ref.get());
            System.out.println("OK");
        }The test result is:
    the ref and the 110 object are not cleared before throw "OutOfMemoryError".
    Why?

    Well, for a start the result of boxing 110 is a
    reference to a static Integer object - Integer has
    predefined instances for numbers up to 128, I
    believe. So there's a strong reference to it, and it
    can't be cleared. The ref variable won't be cleared,
    because it's a strong reference to a WeekReference
    object.Yes, you are right. If I change 110 to 1000. it was cleared.
    Thanks.
    Your has table stuff is wrong (you need to use %
    length not & length, and allow for synonyms, i.e.
    different objects with the same hashCode), might as
    well stick to HashMap. You need a seperate key anyway
    to find the appropriate object in a cache.why '% length', not '& length'?
    It 's allowed to cover by the object with same hashCode.
    here the cache is for huge number object(may more than 10,000, 000).
    It's more important to save space and improve speed if match probability > 90%. not nedd to find the appropriate object for each key.
    You should also use a cleanup thread. Create a
    reference queue and attach the SoftReferences to it,
    then a cleanup thread deletes the entries from the
    hashtable when their references are cleared. The
    requires extending the SoftReference class to add the
    key information needed to find and clear the hash
    table entry.yes. thank your advice.

  • Logical and physical clear in ASO

    Hi There,
    I found one statement for Logical and physical clear in essbase dbag
    The process for logically clearing data completes in a length of time that is proportional to
    the size of the data being cleared.
    The process for physically clearing data completes in a length of time proportional to the
    size of the input data, not to the size of the data being cleared
    What does size of the input data actually means? How it is different from data being cleared.
    Thanks.

    What is interesting with these statements is based on them, you would think a logical clear would be slower than a physical clear. In reality, it is vastly faster. I took a 30 minute physical clear down to about 40 seconds with a logical clear. Logical clers create offsetting entries from the main cube in a slice to produce a result whila a physical clear deletes the actual data. The one thing about logical clears is rather than have #missing for cleared intersections you get zeros

  • My question is How to do old 4S to new 5 S to save same into phone but can not do ask someone last night and did not help me as I am deaf and not clear and Please man told me download from computer and I am not understand at all

    Yesterday We went to At and T store and they told me to download from old phone to new phone and I am really upset and I got Icloud and prove but part of still in 4S and has not go in 5S and that is biggest problem and no commuication that woman stay follow what she said but still not working so I do not know what else to do my do not understand and I would like to have someone do for us and AT and T store can not do that part so Told me Apple store and I called last night talk to some one on Apple store but told me that no go back to AT and T store so now total confuse and I am not get anywhere so and why they will not do it so therefore I do not think computer that not clear for us because we have no experince in computer program for this so both are deaf and not clear so over 50 years age and so we need face someone to do for us and told us do our self which is total upset us more so because my twins are in Orlando and can not call them because of problem contiunes in heart so I need someone who we can trust and help us. I do have IPAD mini and almost lost my calls to my twins and today I think get back but not 100 % so I am kind upset and who email us or I will have to go Apple Store and see if they know personal.

    Open this support document http://support.apple.com/kb/HT2109 print it from the computer and follow the steps there. You need to backup your data from the first device and then restore that to the new device.

  • FBL3N - line item visible both as open item and as cleared item

    Hello,
    Please can you tell me possible reasons for which I see the same line item in FBL3N as an open item when I check "open items" and as cleared when I check for "cleared items".
    Thank you !
    Daniel N.

    There is a small correction:
    It is not partial it is residual.
    In case of partial your original document will be intact - Open items will show debit, credit and the balance.
    In case of residual, your original amount will be deducted and a new entry gets posted as if there is a new transaction. For example from 100 USD if 40 USD has been cleared, then two line items will be shown in 40 as cleared items and a new line 60 will be generated in open items 60. But, this 60 will have different document number.
    I think there is some issue the way in which selection criteria has been selected.
    Please do not see the open items at a key date. Because that date it might be open item, later at a stage it might have become a cleared item.
    Do not restrict any dates and see the total items (cleared items and open items) and let me know if the same document is showing as cleared as well as open. This is more unlikely and I have not seen.
    Regards,
    Ravi

  • Gr and ir clearing

    hi,
    may i know why need to use F.13 to clear the GR and IR clearing account?
    why same clearing account in GR and IR not able to be cleared automatically when do miro?
    thanks

    Hi
    We use F.13 because,
    This process matches goods receipt and invoice receipts by purchase order number and line item.  This results in the movement of the goods receipt and invoice receipts to a cleared status (matched documents).
    Goods receipts and invoice receipts must exist in the system.
    Hope this will be helpfull
    Regards
    Arun

  • Hi I'm running Addressbook and cannot clear previous entry easily when searching my data base of around 5,000 contacts.    I prefer to view in All contacts on a double page spread with details on the right page.  Searching doesn't seem to work correctly i

    Hi I'm running Addressbook and cannot clear previous entry easily when searching my data base of around 5,000 contacts. 
    I prefer to view in All contacts on a double page spread with details on the right page.  Searching doesn't seem to work correctly in this view.
    It's always the second search that is problematic.
    I've tried typing over and all it seems to do is confine the search to the the entries that have come up for the previous search.
    I've tried to use the x to clear the previous entry and then type the next search, same problem.  The only way seems to be to move from "All Contacts" to "Groups".  Then the searched name appears and I can return to All Contacts to see full details.
    Surely three key press' are not the way it's supposed to work?
    FYI
    Processor  2.7 GHz Intel Core i7
    Memory  8 GB 1333 MHz DDR3
    Graphics  Intel HD Graphics 3000 512 MB
    Software  Mac OS X Lion 10.7.3 (11D50d)
    Address book Version 6.1 (1083)
    MacBook Pro, Mac OS X (10.7.1), 8Mb RAM 2.7Ghz i7

    AddressBook experts are here:
    https://discussions.apple.com/community/mac_os/mac_os_x_v10.7_lion#/?tagSet=1386

  • HT1202 I have just bought a new I pad 3 and want to give my I pad 2 to a friend. What will I have to do to clear my info on the old I pad and set it up on my new one? How are apple I D effected and passwords cleared?

    I have just bought a new I pad 3 and want to give my I pad 2 to a friend. What will I have to do to clear my info on the old I pad and set it up on my new one? How are apple I D effected and passwords cleared?
    Any advice welcome.

    To clear to old before passing it on, open the Settings app and tap on General (left hand menu). Scroll down and tap on settings, then tap on Erase All Content and Settings.
    If you have been synching the iPad to iTunes on a computer, you should also have backed it up. If you havn't backed it, you will want to do so before clearing the settings and use the back up to set up your new iPad.
    You may dinf soem of the articles here useful:
    http://www.apple.com/support/ipad/syncing/

  • Bank statement and bank clearing document splitting

    Hi,
    We have main bank and bank clearing accounts classified as cash category.
    Our bank statement uses a Z document type that posts transactions such as:
    - debtor to main bank
    - vendor to main bank
    - expense to main bank
    - revenue to main bank
    Thereafter, the bank clearing that is done between main bank and bank clearing account (so a cash to cash rule is needed based on the GL account classification)
    We needed to use an unspecified posting rule to cater for the bank statement posting as the standard did not allow us to add vendor, debtor, expense, revenue as base item categories. But it doesnt allow us to add cash to cash.
    How should we configure document splitting to cater for this?

    Hi ,
    First of all  i hope you are clear with the concept of Incoming , otugoing and main bank account that we need to create 3 or more diffrent bank accounts for reconcilliation purpose .
    the case here is that you cant to do a manual statement upload then in that case you will have to take care of following things .
    How is the information transferred from FICA to FICO means along with the reconcilliation key what else information are you passing on to FI in the documents .
    Secondly in the bank statement are you getting the reconcilliation key ??? or what information are you getting in the bank statement ???
    because the integration of FI and FICA is the reco key and it becomes very crucial for you to have the same in the bank statement .
    thirdly , Use the manual reconcillaiton functionality provided in FI for reconciling the same , where in you will have to configure the manual bank statement functionality and by using the T code ff67 you can reconcile it .
    Hope this suffices the prupose .
    Do revert back in case of any other queries .
    cheers ,
    dewang

  • I had OS Maverick and downloaded OS X Yosemite and then cleared the mistakenly cleared the hard-drive while trying to re-download OS Maverick and now should I re-download OS X Yosemite in attempts of getting the pictures, videos, and documents back?

    I had OS Maverick and downloaded OS X Yosemite and then cleared the mistakenly cleared the hard-drive while trying to re-download OS Maverick and now should I re-download OS X Yosemite in attempts of getting the pictures, videos, and documents back? 

    No; try using a data recovery product such as the ones listed here. Don't write anything else to the drive until the files are recovered or you choose not to recover them.
    (120682)

  • Posting type 9 reset and reverse clear

    Dear Expert,
    In case of bank statement has information that the transaction is cancelled, how can we handle this kind of transaction?
    I see in posting rule, there is posting type '9' reset and reverse clear. However when I setup and run it foreground, system will calll tcode FBRA in which we have to fill in FI document number. This FI document can't be identified in the bank statement anyway. The business case may be check bounced, for example.
    So how can we setup the posting rule with posting type '9' to cancel the FI document originally posted from the previous transaction?
    Please kindly suggest.
    Rgds,

    Try to find out the mathcing field from Document Header data to identify it.
    Thanks

  • How to offset Cenvat suspense and cenvat clearing

    Hi
    Please tell me how to clear cenvat suspense and cenvat clearing in case of sales return and purchase return? pls give the T-codes and the entries
    thanks in advance

    Hi Dina/Experts,
    I would like to know the Accounting that takes place while Capital project is setup to collect costs as follows:
    Supplier Cost for Architectural drawings: $2,000.00
    Supplier Invoice for building Contractor: $5,000.00
    Supplier Invoice for building Permit Penalty: $ 100.00
    $7,100.00
    Employee Labor project Management: $1,400.00
    Employee Expense Report for Misc. Costs: $ 800.00
    Cost for Usgae of Company Car: $ 150.00
    TOTAL COSTS FOR PROJECT X $9,450.00
    =======
    What is the Accounting in AP for the Capital Project? What is the Accounting that would take place once the Costs are interfaced to Projects fom AP?
    What is the Accounting that takes place when you generate Asset Lines if at all?
    What is the accounting that takes place once the Project Cost are Interfaced to Fixed Assets?
    Thanks,
    Arun

  • Cenvat suspense and cenvat clearing

    Hi
    Please tell me how to clear cenvat suspense and cenvat clearing in case of sales return and purchase return? pls give the T-codes and the entries
    thanks in advance

    Hi
    Please tell me how to clear cenvat suspense and cenvat clearing in case of sales return and purchase return? pls give the T-codes and the entries
    thanks in advance

  • Photo Booth Help! My photo booth screen is very very dark. I thought it was the screen but its at the brightest it can possibly be! So I grabbed my mothers MacBook Pro and It's much lighter and more clear. I have just the regular macbook. Please Help.

    My photo booth screen is very very dark. I thought it was the screen but its at the brightest it can possibly be! So I grabbed my mothers MacBook Pro and It's much lighter and more clear. I have just the regular macbook. I also used the my camera on tumblr and it came up like my mothers. So could it just be photo booth? I also have no idea how to find out which operating system is downloaded. This is preowned.

    Use the trackpad to scroll, thats what it was designed for. The scroll bars automatically disappear when not being used and will appear if you scroll up or down using the trackpad.
    This is a user-to-user forum and most people will post on here if they have problems. You very rarely get people posting to say there update went smooth. The fact is the vast majority of Mountain Lion users will not be experiencing any major problems with the OS, or maybe with apps which are not compatible, but thats hardly Apple's fault if developers don't update their apps.

  • I want to ask company when user update to ios7 it stuck all of device and not clearly about apple id to active how to solve it or just keep all of device into recycle because can not use?

    i want to ask company when user update to ios7 it stuck all of device and not clearly about apple id to active how to solve it or just keep all of device into recycle because can not use?

    You need to enter the Apple ID and password that was used to set up/activate the phone. There is no way around this.

Maybe you are looking for

  • In the new iphoto app, why can't i save multiple images to camera roll at once?

    why can't i save multiple images to camera roll at once? it seems i can only save one at a time and its very frustrating.. the options seem to be there, they are just greyed out and i cant click on them. at first i thought its because the images were

  • Position of eps-files in anchored frame

    Hello, I'm sorry but the subject was too large to put it in the subject-field. Subject: position of eps-files (Mac Os 9, Illustrator 9.0, preview tiff black/white) is not correct after saving eps-files (preview macintosh black/white) I want to upgrad

  • RFC connexion between R3 and CRM

    Hello, I have created a RFC connexion between My R3 (HF1CLNT300) and CRM( HF6CLNT300)  using SM59.. but when i test it i have the this :             Test connexion  HF6CLNT300 Type connexion      Connexion R/3 Interr. Do you know what does mean Inter

  • Can't delete a logical volume group created from a blank disk image

    Hi all, I'm a recent convert from Windows, so do bear with me while I grapple with all the new terminology. Basically, here's the problem: I've been trying to create an encrypted drive and have been at it for a few hours now. I ended up with two 'log

  • Moving Patch Channel Strips to Set Level

    I have a patch setup I would like to move to a Set level, complete with it's layout, channel strips, plug-ins, and instruments. Is this possible in MainStage 1? How? And, iƒ not, is it possible in MainStage 2? Thanks.....