Frequently Asked Questions

Sep 27, 2022 - 07:18am

 [F] Frequently Asked Questions  / Common Problems and Solutions  / Troubleshooting  / Macro or template troubles.  / WCJS (Server Side JavaScript)  /

WCJS and memoryReclaim for out of memory errors

Rate This FAQ
 (Not yet rated)

Created On: 5 Jun 2002 10:21 am
Last Edited: 5 Jun 2002 10:21 am

Question Printer Friendly

I am getting an "out of memory" error when handling large amounts of data.

Answer

If you are getting an "out of memory" error when handling large amounts of data in a WCJS function, it could be because memory reclaiming in the latest core JavaScript 1.5RC1 source, which we use, is not as robust as it was in previous versions.

The solution is to use the memoryReclaim() function in your loops.

What we usually do is set a counter and only call this occasionally, since the reclaim does take a while to run. For example, the following would only call memoryReclaim once out of each 10 times through the loop:

Example
   var reclaim = 10;
   for( ... ){
     ...
     if( --reclaim == 0 ){
       memoryReclaim();
       reclaim = 10;
     }
   }