Link to home
Start Free TrialLog in
Avatar of ORScom
ORScom

asked on

VBScript runtime (0x800A0007) Out of memory

When I run the code below I get this error message. The XML file that I'm searching through is about 2.5 MB and has about 22,000 records.

Any ideas why I'm getting this error and how to correct it?

Error message:
Error Type:
Microsoft VBScript runtime (0x800A0007)
Out of memory: 'objLst.item'


The error message references the line of code that reads:
      Set objHdl = objLst.item(tmp)



The code:
Function FindFirst(searchItem, SearchResult)

      Dim tmp

      tmp = SearchResult-1

      Set objHdl = objLst.item(tmp)
      LastName = objHdl.childNodes(0).text
      DisplayName = objHdl.childNodes(1).text

      If Left(LastName,Len(searchItem)) = searchItem then
            FindFirst = FindFirst(searchItem, tmp)
      Else
            FindFirst = SearchResult
      End If

End Function 'FindFirst
Avatar of purplepomegranite
purplepomegranite
Flag of United Kingdom of Great Britain and Northern Ireland image

Ouch.

The error message says it all - out of memory.

You are using recursion, and on an XML file of the size you reference, I am not surprised you are out of memory - every call to FindFirst increases the amount of memory needed.  I would suggest that if dealing with a file of that size, you need to find a method of achieving the result WITHOUT recursion.
Though it must be said, I can't actually see what this code IS doing... what result are you wanting from this function?
Avatar of ORScom
ORScom

ASKER

This is a part of an application that searches through an XML file and returns all records with a user supplied last name. The XML file is alphabetically sorted by last name.

Earlier in the script I used a binary search algorithm to quickly find an occurrence of the last name with out having to loop through all of the records. But, I need to make sure that the record that is returned is the first record with that last name. So, that's where this FindFirst function comes into play.

Later, after the application finds the first record with this last name it displays all of the records containing the last name.

The XML file I'm using looks something like this:

<?xml version="1.0"?>
<MyXMLfile>
      <header>
            <lastBuildDate>6/10/2008 12:44:49 PM EST</lastBuildDate>
      </header>
      <Individual>
            <LastName>AALBERTS</LastName>
            <DisplayName>AALBERTS, WILLIAM</DisplayName>
      </Individual>
      <Individual>
            <LastName>AARON</LastName>
            <DisplayName>AARON, MICHAEL</DisplayName>
      </Individual>
      <Individual>
            <LastName>ABBEY</LastName>
            <DisplayName>ABBEY, CAROLYN</DisplayName>
      </Individual>
      <Individual>
            <LastName>ABBEY</LastName>
            <DisplayName>ABBEY, MICHAEL</DisplayName>
      </Individual>
      <Individual>
            <LastName>ABBOTT</LastName>
            <DisplayName>ABBOTT, ROBERT</DisplayName>
      </Individual>
      <Individual>
            <LastName>ZYWICKI</LastName>
            <DisplayName>ZYWICKI, FAYTE</DisplayName>
      </Individual>
</MyXMLfile>
I think the attached should accomplish this (without recursion).
Function FindFirst(searchItem, SearchResult)
 
      Dim tmp
      tmp = SearchResult
 
		LastName=searchItem
		while Left(LastName,Len(searchItem)) = searchItem and tmp>0
			tmp=tmp-1
			Set objHdl = objLst.item(tmp)
			LastName = objHdl.childNodes(0).text
			DisplayName = objHdl.childNodes(1).text
		wend
      If tmp<(SearchResult-1) then
            FindFirst = tmp+1
      Else
            FindFirst = SearchResult
      End If
 
End Function 'FindFirst

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of purplepomegranite
purplepomegranite
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ORScom

ASKER

purplepomegranite,

This works great! Thank YOU!

OK, just so I understand...

Looping through the 22,000 some records in the XML file wasn't eating up the memory, it was the repeated calls to the FindFirst function?
Recursion is an absolutely great technique in some situations - it can make what would be long code short and elegant.  However, it is resource intensive in the sense that every single time the function is called again more data goes onto the stack (or is it heap?  I'm a little rusty on which one it is!).  There is only limited memory available for the stack, so too many function calls will cause the dreaded out of memory error.

And to clarify, looping through 22000 records shouldn't be an issue at all.  I have written routines that need to process far more than this.  But you need to avoid recursion if the recursion is going to be deep before it gets to it's base (i.e. the last function to be called before they are all returned) - because you will run out of memory before it gets there.

I just looked up recursion on Wikipedia to see if that would explain it better: http://en.wikipedia.org/wiki/Recursion_%28computer_science%29

To be honest, that article doesn't help with my understanding of recursion at all!  However, I grew up with Sinclair machines (a whole 1k RAM) so learned recursion and it's limitations that way.

Hopefully that makes some form of sense...