This is ASPLint.vbs:
Actually, it’s more like ASP-VBScript Lint. Sorry, JS programmers. Sorry, .NET programmers.
Here’s what it does, and why…
in ASP when you “SET object = …” an object, that object starts occupying memory. If you don’t release that memory (SET object = Nothing), it never lets go of that memory. Even after the page finishes. Even 3 days later. IIS isn’t too sharp about its “garbage collection”.
ASPLint exists to scan a web server directory for files that have objects SET, and never released. It traverses the entire directory tree you start it at, and examines separately, and in context, every ASP page in there. It creates a log of the objects that aren’t closed, by filename, approximate line number and variable name. Should make finding and fixing memory leaks in your ASP apps much easier.
It doesn’t count comments. It doesn’t calculate white-space. It doesn’t have a neat interface. It doesn’t cost $400. It does help solve the memory leak problems I was having.
How it works:
Assign the four variables near the top of the script: strRoot, strTypes, strLogFile, and intLimit. They tell the script what directory to start in, what file types to look at, what logfile to create, and how many errors are a good stopping place (I hate being overwhelmed by errors to fix). Call the script from the command line: cscript.exe asplint.vbs Go get a pot of coffee.
While you’re gone, the script will start in strRoot, and open every file that matches the filetype extensions you gave it. For each file, first any #include-d file is also opened, and chunked together with the current file – just like ASP does when it displays a page on your webserver. This does NOT actually change your file – the chunkin’ happens in memory. Virtual or File types of #Includes both work, although if you use virtual include types to virtual directories, well, that’s just crazy, and ASPLint won’t go there.
Once the entire file (includes and all) has been assembled, ASPLint starts from the top and looks for any occurence of “set (somevariable) =”. I’ve attempted to be smart about it – it’ll find SETs that are on a line by themselves, or are in one of those annoying : colon : separated : lines that gang several instructions onto a single line. Punk. Don’t code that way. Lines that are ‘ commented out get skipped, so the count should be half-accurate.*
If a SET if found, a corresponding SET … = Nothing is also searched. If that’s not found, that filename, approximate* line number and variable name get logged to the logfile you named.
I tried to make the logfile smart enough so that each file’s dangling objects will only be listed once.
I Tried.
* About all those asterisks…
First, you can probably guess that flow-control statements are obeyed in ASP, and skipped in ASPLint.
Consider this:
if 1=1 then set objMe = Some.Object
if 1=0 then set objMe = Nothing
ASP will obviously only perform one of those two commands. Yay for ASP. ASPLint assumes they both worked. Boo for ASPLint. But accounting for Flow-control statements gives me a headache. You should be writing better code than that anyway — I’m not your mother, I don’t clean up after you.
Second, because ASPLint chunks all those included files together, its count of lines from the top of the whole memory chunk isn’t quite accurate. Sure, I try to calculate the space taken by includes, and I do a decent job of detecting objects opened/closed in includes instead of the file that included them, but there’s a really good chance the line numbers you see in the log will be wrong. The degree of wrong goes up as the number of includes increases. I didn’t feel like figuring the whole thing out. Given the right filename, the right variable name and an approximate line number, you should get close enough to find the little bugger yourself.
There. Now you know what I was planning. You can browse/change/steal the code below, and make any use of it you want. Is that a GPL License? Creative Commons? I dunno. I don’t care. Do what you like, but when you speak of me, speak kindly.
Oh, and realize there’s probably bugs in here (inefficiencies, stupidities, vagueries, etc.). I know that. But I have a real job to get done, and this was just a hacked-together means to an end that I’m giving the world for free. Complain not. If you DO happen to fix or enhance something, please do send me a copy – Jonathan @ this website. I’ll put it back on my website for the rest of us ASP coding peons to enjoy.