View Full Version : Out of memory errors (update)

02-22-2006, 08:18 PM
I am trying to create a search script but I am running into an out of memory error. Here is the search subroutine which loops multiple times:

sub SubSearch()
path = folderarray(arraycounter) 'set path to current folder to search

if arraycounter > 0 then
temp = arraycounter - 1
folderarray(temp) = 0
end if

' Set fso = server.CreateObject("Scripting.FileSystemObject")
set fo = fso.getfolder(path)

' response.write(fo & "<br>")

for each subfolder in fo.subfolders
temppath = subfolder

redim preserve folderarray(counter)
folderarray(counter) = temppath
counter = counter + 1

for each file in fo.files
if fso.getextensionname(file) = "mht" then
set readfile=fso.opentextfile(file,1,false)
set readfilename=fso.getfile(file)

if file.size > 0 then 'if something in the file, read it MAY NEED TO CHANGE
exit for
end if

urlfilename = replace(mid(readfilename, 29),"\","/")
urlfilename = replace(urlfilename," ","%20")

'Necessary to keep it from searching through the picture garbage text
find_html = instr(file, "</html>")
file = left(file, find_html)

'The actual search part
isinfile = instr(1, file, search, 1)
if isinfile > 0 then
'Pulls the page title out
title_str = instr(file, "<title>")
title_str = title_str + 7 'adds 7 to start right after <title>
title_end = instr(file, "</title>")
title_read = title_end - title_str
number = number + 1

response.write(number & ": ") %><a href=<% response.write(fusionurl & urlfilename) %> target="_blank"><% response.write(mid(file, title_str, title_read)) %></a><%

starthere = isinfile - 10
end if

set readfile=nothing
set readfilename=nothing
end if

arraycounter = arraycounter + 1

' set fso=nothing
set fo=nothing

' response.write("Arraycounter = " & arraycounter & " and Counter = " & counter & "<br>")

if arraycounter = counter then 'if no other folders to search, then done
response.write("Script Done.<br>")
else 'if more folders to search, call SubSearch
end if
end sub
It works as long as there are less than about 130 documents. It gives me the error about 9 lines down, set fo = fso.getfolder(path). I made sure to set fo =nothing at the bottom, any ideas why I am getting this? Thanks.

03-01-2006, 04:17 PM
After many hours of messing around with it, I have come to the conclusion that it is my array that is taking up all the memory. I deleted about 40 of the 160 or so folders but left the files, and the script runs without problems. I tried editing the script where the array never gets larger than maybe 130, but I still get that error. Can anyone see anything wrong with the way the array is done and possibly a way to fix it? Thanks.