Memory Fragmentation

ron_mickaels@bdis.com
Wed, 30 Aug 95 11:00:32

Leon Martin writes:
In addition to the comments made in other replies, there is another point
worth noting that continuously trips up our Mac users ......

If you are in the habit of opening a few (or many!) applications at once,
and then hope to recover the memory when closing them, they must be closed
in the reverse order of opening.

e.g. if you open 1,2,3,4, you cannot close 2 and necessarily get `that
amount' of memory back. Depending on how much memory the next program
requires (maybe CellQuest set at 6MB), you may get the `out of memory'
message. This confuses users all the time as the Mac system (`About This
Mac' from the Apple Menu) tells you there is heaps of available memory!

Basically the current MacOS versions do not compact the unused memory. The
only way to do this is a reboot. However, if you use RAM Doubler and/or
OptiMem I think one or both of these programs will compact these memory
`holes'.
---------------------
Leon is correct. RAM can get fragmented just like your hard disk. It's easy to
verify. Just open the "About this Macintosh" dialog in the Finder and open some
Applications. Watch the "Largest Unused Block" number, because this is the
biggest partition that the system will allocate to a new application . Close one
of the middle apps. You'll notice that the largest unused block doesn't get any
bigger.

The memory manager allocates a block of memory to an application, and that's
where the application lives. It never moves from that partition. Because of
this, you can get fragmentation problems if you're always opening and closing
applications. Also, applications need to live in contiguous blocks of memory.
So fragmentation can really cause you grief.

For example, say that you have 14 Megs of RAM (after the system loads) and you
launch 3 applications. (Applications are loaded into memory from the high point
of memory downward using a "best fit" algorithm, the system loads from the
bottom up).

Just to emphasize how memory fragmentation can become a problem, lets say that
you launch Photoshop at 8 MB, Calculator at 128 KB and Excel at 5 MB. This would
leave me with an unused partition of a little less than 1 MB.

MEMORY MAP
========================== =
Photoshop
(8 MB)

--------------------------
Calculator (128k)
-------------------------- Total Free Memory
Excel 1 MB
(5 MB)

-------------------------- =
FREE (1 MB) Largest Free Block
1 MB
-------------------------- =
SYSTEM SOFTWARE
========================== =

Now lets say that you want to launch an Application that needs 10 MB to run. If
you close Photoshop and Excel (13 MB total) I might expect to have enough memory
to launch a 10 MB application. But this is not the case. Here's what the memory
map would look like.

========================== = =
FREE
(8 MB) Largest Free Block
8 MB

-------------------------- =
Calculator (128k)
-------------------------- Total Free Memory
FREE 14 MB
(6 MB)




--------------------------
SYSTEM SOFTWARE
========================== =

Even though there is a total of 14 MB of memory available, the largest partition
available to load an application into is 8 MB. Therefore, the system would tell
you that there was not enough memory to load a 10 MB application.

What I do when I get the out of memory dialog (and I know that I have enough
free memory) is open the "About this Mac" dialog and start quitting applications
until I get a block big enough to open the app that I want. It is not necessary
to restart your system to de-fragment memory since the System Memory Heap and
the Application Heap are in different parts of RAM. Sometimes, however, you may
need to quit all of the open applications just to consolidate memory, and then
re-launch the ones that you need (this should rarely need to be done).

Appications that you always want open (like an e-mail program, Meeting Maker)
should be open at startup time by making an alias of the application and putting
the alias in the "Startup Items" folder of your System Folder. The memory
manager always tries to allocate a new partition from the top of memory and the
system lives in the bottom of memory. By having apps that you always want to
have open load at startup, you can help prevent memory fragmentation.

By the way, RAM Doubler does attempt to defragment memory, but beware! There are
quite a few major applications that don't like RAM doubler. I only use RAM
Doubler on my PowerBook, and then only when I absolutely have to! Most of the
time I deinstall it and just live within my meager memory constraints.

Ron Mickaels


Home Page Table of Contents Sponsors Web Sites
CD ROM Vol 2 was produced by staff at the Purdue University Cytometry Laboratories and distributed free of charge as an educational service to the cytometry community. If you have any comments please direct them to Dr. J. Paul Robinson, Professor & Director, PUCL, Purdue University, West Lafayette, IN 47907. Phone:(317) 494-0757; FAX (317) 494-0517; Web http://www.cyto.purdue.edu EMAIL robinson@flowcyt.cyto.purdue.edu