Solved

VBScript runtime (0x800A0007) Out of memory

Posted on 2008-06-11
7
1,578 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This is about my first experience with programming Arduino.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Progress

617 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