Persits Software, Inc. Knowledge Base Articles

Not enough memory error

Problem Description

When trying to open an image with AspJpeg, the following error may occur sporadically:

Persits.Jpeg.1 error '800a000c'
not enough memory

Solution

NOTE: The information in this article is preliminary, pending confirmation from independent testers. Please let us know if the information in this article has helped you solve the issue.

Reducing Memory Fragmentation

When you call AspJpeg's Open or OpenBinary methods, the component attempts to allocate a chunk of RAM on the server big enough to store the decompressed version of the image for processing (resizing, etc.) Once AspJpeg is done processing the image, the memory is deallocated.

Repeated allocation and deallocation of large chunks of RAM may lead to memory fragmentation, a situation when there are no contiguous blocks of available memory large enough to accommodate the needs of an application, even though the total amount of free RAM is plentiful. To clean up memory fragmentation, the application needs to be recycled.

In IIS 6.0+, you should create a separate Application Pool for the script that uses AspJpeg. To reduce memory fragmentation, this AppPool should be recycled more aggressively than what the default settings provide for.

The Recycle worker processes option is set to 1740 minutes (29 hours) by default. Try reducing this setting to a smaller number such as 240 (4 hours.) Also, try enabling the Maximum virtual memory recycling option. Other fine-tuning options can be tried as well, if necessary.

For more information on fine-tuning application pools, please read the Microsoft TechNet article Configuring Application Pools in IIS 6.0 by Brett Hill.

Optimizing Operations on Images

Image resizing being extremely CPU- and memory-intensive, the amount of operations your application performs on images should be kept to a minimum. Dynamic thumbnail creation for every page view should be avoided at all costs. Wherever possible, web pages should serve pre-created thumbnails.

For example, consider a real-estate web site displaying thumbnails of properties for sale:

<IMG SRC="thumbnail.asp?id=1">
<BR>
<IMG SRC="thumbnail.asp?id=2">
<BR>
<IMG SRC="thumbnail.asp?id=3">
<BR>
<IMG SRC="thumbnail.asp?id=4">
...

The script thumbnail.asp dynamically creates thumbnails of images:

<%
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Path = ObtainPath( Request("id") )
Jpeg.Open Path
Jpeg.PreserveAspectRatio = True
Jpeg.Width = 100
Jpeg.SendBinary
%>

This may work fine in a testing environment but once thousands of users hit this site, the web server will slow to a crawl. It would be much more efficient to pre-create all thumbnails of the images just once instead of creating them over and over again for each page view thus killing the server's performance and running into memory fragmentation issues described above.