Solved

VBScript runtime (0x800A0007) Out of memory

Posted on 2008-06-11
7
1,523 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article will show, step by step, how to integrate R code into a R Sweave document
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

707 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

17 Experts available now in Live!

Get 1:1 Help Now