Java theory and practice: Plugging memory leaks with weak refere. For garbage collection (GC) to reclaim objects no longer in use by the program, the logical lifetime of an object (the time that the application will use it) and the actual lifetime of outstanding references to that object must be the same.
Most of the time, good software engineering techniques ensure that this happens automatically, without us having to expend a lot of attention on the issue of object lifetime. But every once in a while, we create a reference that holds an object in memory much longer than we expected it to, a situation referred to as unintentional object retention.
Memory leaks with global Maps The most common source of unintentional object retention is the use of a Map to associate metadata with transient objects. Let's say you have an object with an intermediate lifetime -- longer than that of the method call that allocated it, but shorter than that of the application -- such as a socket connection from a client. Listing 1. Back to top Identifying memory leaks. How The Kernel Manages Your Memory. After examining the virtual address layout of a process, we turn to the kernel and its mechanisms for managing user memory.
Here is gonzo again: Linux processes are implemented in the kernel as instances of task_struct, the process descriptor. The mm field in task_struct points to the memory descriptor, mm_struct, which is an executive summary of a program’s memory. It stores the start and end of memory segments as shown above, the number of physical memory pages used by the process (rss stands for Resident Set Size), the amount of virtual address space used, and other tidbits. Within the memory descriptor we also find the two work horses for managing program memory: the set of virtual memory areas and the page tables. Each virtual memory area (VMA) is a contiguous range of virtual addresses; these areas never overlap. In Windows, the EPROCESS block is roughly a mix of task_struct and mm_struct. Linux has functions to read and set each flag in a PTE.
Things could have been different. Inside the Savant Mind: Tips for Thinking from an Extraordinary. Daniel Tammet is the author of two books, Born on a Blue Day and Embracing the Wide Sky, which comes out this month.
He’s also a linguist and holds the European record for reciting the first 22,514 decimal points of the mathematical constant Pi. Mind Matters editor Jonah Lehrer chats with Tammet about how his memory works, why the IQ test is overrated, and a possible explanation for extraordinary feats of creativity. LEHRER: Your recent memoir, Born on a Blue Day, documented your life as an autistic savant. You describe, for example, how you are able to quickly learn new languages, and remember scenes from years earlier in cinematic detail. Are you ever surprised by your own abilities? TAMMET: I have always thought of abstract information—numbers for example—in visual, dynamic form. In my mind, numbers and words are far more than squiggles of ink on a page. None of this is particularly surprising for me. Another finding, by cognitive psychologists Lera Boroditsky, Lauren A. Talk on x86 Memory Model.