Support > General Discussions

Arrays Not Releasing Memory

(1/1)

falkyr11:
Hi everyone:

I'm new to this forum, so bear with me.

I have a question about memory utilization by arrays.  My concern is that I don't think ScriptBasic releases memory consumed by an array back to the operating system when the array is destroyed.

I am writing an application that queries a MySQL database and stores the query results in an array.  Logically, once I've done what I need to do with the query results, I want to destroy the array and free the memory back up to the OS.

As a test, I wrote a program that creates a huge two dimensional array (2 columns, 10,000 rows) full of garbage text.  I set the program such that when it starts it first waits for an input from the user--just as a pause before it goes ahead and builds the array.  Once the array is built, I wait for another input from the user and then destroy it using UNDEF.

When I run the program I start Task Manager and monitor memory consumption.  When the program first start, 1004K is eaten up.  No problem.  I hit the enter key to get past the first input statement and build the junk array.  The array is built, and memory consumption shoots up to somewhere around 8024K.  Still everything going as expected.  Then I hit the enter key again to destroy the array, but memory utilization does not drop! If anything, it increases a bit! Yet PRINTing one of the junk array's elements proves that the array is now undefined.

So the values stored in the array become undefined, but the memory that was reserved to initially create the array is never released.

Anybody got any thoughts on this and how I might be able to overcome it?

Thanks,
Norm

Support:
Norm,

I wonder if converting the array to a simple null string would release the memory.

John

P.S.

Sorry for the delayed response.   :(

Support:
Norm,

Have you tried the following?

undef myarray


--- Quote from: "ScriptBasic Documentation" ---
This command can also be used to release the memory that was occupied by an array when the variable holding the array is set to undef.

--- End quote ---


When you exit a program all memory should be released. I haven't notice this problem and I create some very large strings and arrays. Have you tried to create a large array without populating it with the MySQL interface and see if the memory is released? What OS are you running under?

I'll try to reproduce this on my end. If you can send me the relevant code, that would also help Peter and I track this down. I'm surprised no one else has mentioned this before.  :?:

John

verhas:
ScriptBasic does not release the memory back to the operating system. It is greedy by design. It releases the memory to its own memory handling layer (implemented in myalloc.c) and reuses it when needed.

Navigation

[0] Message Index

Go to full version