Re: Reclaiming Memory




"Raj" <raj@xxxxxxxxxxxxxx> wrote in message
news:uET%23fJgdHHA.2332@xxxxxxxxxxxxxxxxxxxxxxx
Hello,

Good evening.

I need to know:

#1 After running an application how to clear memory used by that
application?

Unless you are using the Win32API to create certain kinds of handles (for
example, handles to device context, memory addresses, etc.), VB is actually
pretty good at cleaning up. IOW, VB will clean up references to objects all
on it's own. However, it's considered good practice to this this manually
yourself when the object reference is no longer needed. The main reason
being why use memory unnecessarily. Most memory leaks are caused by 3rd
party DLLs and OCXs that don't clean up after themselves. For example, if
you instantiate an object from a DLL, VB will clean up THAT reference by
itself, but the object in the DLL may create references to object, create
handles, etc., that IT doesn't clean up properly.

#2 I am storing an array of objects into a variant. Once all the
activities are completed I need to set that variant to nothing. Something
similar to:

Set con=New Adodb.Connection
----
----
----
----
Set con=Nothing


It's a little unusual to use an array to store object references. I don't
know if VB would clean up, on its own, object references assigned to
elements of an array, particularly if the data type of that array is
Variant. If you're going to continue to use a Variant array for these object
references, I'd recommending looping through the array and seting each
element to Nothing. Might not be necessary, but like I said, it's a little
unusual to use a variant array for what you apparently are (at least I'VE
never seen or heard of doing this before, but I'm sure people have).


#3. Need to know setting variant to vbEmpty is as equal as setting
Nothing


As explained, Empty and Nothing are not the same thing. Empty applies ONLY
to the Variant data type and means that the variable (or elements of an
array in your case) is uninitialized. Nothing applies ONLY to object
variables (variables used to hold a reference to an object, and usually
declared as either the generic Object type or a specific object type) and
means that the object variable does not reference any object. I really don't
know if setting your Variant array holding object references to vbEmpty
would be the same as setting it to Nothing, or indeed if either of those
would be the same as setting each element of the array to Nothing.


--
Mike
Microsoft MVP Visual Basic


.



Relevant Pages

  • Re: Set / List
    ... Less memory use. ... A hash has an array where it stores Entries, ... Each entry has at least two references. ...
    (comp.lang.java.programmer)
  • Re: Array.Resize question
    ... Only if there are no other references to those objects, ... objects that are now thown out of the array released properly by the CLI?" ... Garbage Collection only occurs when the system is low on memory. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: There is no sizeof in a managed language, right?
    ... I was trying to find how much memory is taken up by an array of ints, ... With references and managed languages, what do you use to figure this ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Array of byte of unknown size
    ... The example given in the control's help file is for Visual Basic - so ... same thing with a variant array in Delphi ... I see out of memory errors in your future. ...
    (borland.public.delphi.language.objectpascal)
  • Re: Will memory get over-used?
    ... or have a poor memory.. ... still has array maximum sizes limited to 2GB" ... array will be that of a bunch of references, ... Arrays are not the same as objects and ArrayLISTs ...
    (microsoft.public.dotnet.languages.vb)