Re: Need help with "out of memory Errors" on server script
Re: Need help with "out of memory Errors" on server script
- Subject: Re: Need help with "out of memory Errors" on server script
- From: Steven Angier <email@hidden>
- Date: Tue, 18 Sep 2001 10:20:45 +1000
- Organization: Macscript.com
"John R. Head" wrote:
>
I have an application that is running constantly watching folders and
>
depending on file type, doing some work on them and communicating results
>
via URL ACCESS to an app on WebObjects.
>
>
We are getting this error message "out of memory" after an extended period
>
of this application watching folders. We have played with settings and all
>
to no avail.
AppleScript applications have memory leaks. One of the more common ways to run
in to them is by trapping errors in try/on error blocks.
My tests have shown a net memory loss of 1 bit for every 15 or so errors
trapped (see the test code below). This is a very strange amount. Maybe the
Apple people (Chris) can explain the how and why (and hopefully plug the leak).
>
There are 2 folders it watches, and one folder has 10 inside of it. But if
>
it has been about 3 hours or so (I guess since we never can see it actually
>
produce the error,) but only when we come in the AM is it showing this
>
message. There is an Idle routine and about 15 pages of scripts that it is
>
working through till it finds the right kind of file. But there appear to be
>
no problems there with the script and its memory during its working phase,
>
only during the idle loops with nothing to do.
I have found that the most reliable solution is to allocate a seemingly
rediculous amount of memory to the application (say 2 MB or more). This gives
your script apps a significant leak buffer. I find that this amount of memory
keeps the app running for longer than the average uptime on the box/process (3
or 4 weeks with many of our processes). This amount of extra RAM will, of
course, vary.
>
Is there some way to purge memory, or defragment it so we do not experience
>
this problem within the script. I have considered quitting the script every
>
4th time or so, I do have an AS application that watches to make sure it is
>
running.
You could do that, but it will probably be overkill. Similarly, a daily restart
of the app or machine may also be overkill and may increase the risk of more
downtime due to start-up errors.
I think that if you give the app enough RAM to keep it going for several weeks,
you will find that you never run out of memory because you will probably
restart the process or the box within that time.
Try downloading Memory Mapper by R. Fronabarger from Version Tracker and just
monitor the free memory lost in your application over the course of a few hours
and days. You can then quantify the actual memory loss and extrapolate the
practical amount of memory you should give your applications.
Good luck,
Steven Angier
Macscript.com