Solved

VBScript runtime (0x800A0007) Out of memory

Posted on 2008-06-11
7
1,539 Views
Last Modified: 2008-06-11
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
0
Comment
Question by:ORScom
  • 5
  • 2
7 Comments
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21760159
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.
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21760168
Though it must be said, I can't actually see what this code IS doing... what result are you wanting from this function?
0
 

Author Comment

by:ORScom
ID: 21760470
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>
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21760682
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

0
 
LVL 24

Accepted Solution

by:
purplepomegranite earned 500 total points
ID: 21760706
Sorry, indenting was all wrong on that one (though the code is right...).  EE always does strange things to my code when I copy and paste it.  I think the attached should have proper indenting...
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

0
 

Author Comment

by:ORScom
ID: 21761059
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?
0
 
LVL 24

Expert Comment

by:purplepomegranite
ID: 21761482
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...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now