Looking within memory hogs to find offending term

Top  Previous  Next

Sometimes one runs profile and finds that the memory problem is inside a complex statement.  For example, I have been known to regularly run models where report statements are well over 800 lines long containing 40 or so different terms.  Finding a memory use problem in such a long statement still leaves one with the question of where is the problem.  In such cases you can use the comment inserting syntax $Ontext/$Offtext and *'s to deactivate parts of the code.

Namely, if a multi-term piece of code spanning lines 1182 to 1294 uses excessive memory, one could would re-execute the code but split the term so say lines 1240 to 1294 are deactivated (surrounding them with an $Ontext - $Offtext sequence).  Then if the remaining lines still showed use of a lot of memory, I would deactivate further code until the code deactivation greatly reduced memory use.  I would then know that the last section put into the text status contained the memory hogging code.  In turn, I could search further until the exact problematic portion is identified.