Is there a way in Java to do something just before running out of memory. For example, keeping a list of previous document states (for undo) and only removing very old states when memory is about to be exhausted?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You may be able to do something with
SoftReference. Note also the general documentation for the java.lang.ref package. If the objects are only reachable via aSoftReference, they’ll be garbage collected before an out of memory error occurs. Note however that VMs aren’t required to keep those references prior to such an event or make any guarantees about which order they might be cleared in. You might be best combining them with some form of persistence.