views:

307

answers:

2

I have a piece of code that takes several rows from a database and creates a dictionary object which I push into an array.

do while index < rs.RecordCount or (not rs.EOF)
  set dict = Server.CreateObject("Scripting.Dictionary")

  for each x in rs.fields
    temp = x.value
    dict.add lcase(x.name), temp
  next

  set records(index) = dict

  index = index + 1
  rs.moveNext
  set dict = nothing
loop

I usually call set object = nothing when done with a dictionary but do I have to go through the whole array here (records) and set each index to "nothing"?

I am wondering because of memory management and unsure how IIS and ASP handles it.

A: 

No you don't.

The script engine will free those variables as soon as they go out of scope.

The whole 'set objects to nothing' practice is advocated on an implicit 'just in case' thinking by people who haven't bothered to check the facts.

Drop the practice. And read this.

Tor Haugen
A: 
set records(index) = dict
.
.
.
set dict = nothing

You are storing a reference of each newly created dictionary object in the records array. Setting the dictionary object to noting has no effect as a copy of reference to these objects exists in another variable. To really free the memory, you'll have to iterate over the records array and set each array item to nothing. Ofcourse, as Wgaffa pointed out, this is done automatically once the records variable moves out of scope.

Salman A