Cleaning behind you
Ending up a big project, I was brimming with confidence. The code was well structured, it ran fast despite using external web services and on top of that, it worked on test system. Oh boy, did it work. I should have seen a warning sign there. But no. I let my vanity kickĀ in and enjoyed the good times. Yes, everything worked. Until…
…server crashed. With access violation problem. I feverishly scrolled through code, looking for an obvious error, but was unable to locate one at first glance. And than, slowly it dawned on me. I let garbage collection do my own dirty work. Unfortunately garbage collection in LotusScript has a small “feature”. It does not collect and disposes of web service consumers.
This is what my problem was. I created an abstract class that took care of initialization (including service consumer object). Then each data type had it’s own class that inherited from that abstract class. Needless to say that I forgot to add destructor that would clear web service consumer object. So, now, I had n web service consumer objects pointing to the same web service consumer, resulting in a memory leak of a size of an elephant after a huge meal and consequently a server crash.
But enough about me. Cleaning behind you in your code is a good practice. Not only it will make your code run smoother and look more spiffy, but it will also save you from feverish last minute code scrambling, busting your head and yelling like a mad man with a look of a rabid squirrel. So, let’s look what you can do.
1. Use destructors that actually do something useful in your classes.
Having an empty Sub Delete (or none at all) is just not enough. Try clearing your member variables as well. Specially if they are your custom classes, web services, arrays or lists.
2. Don’t be afraid to use Erase statement to clear arrays and lists you don’t need.
Arrays and lists can take up a lot of your servers memory. Specially if you do an array of Notes objects. Be sure to clear them as soon as they are not needed anymore.
Leave a Reply