473,473 Members | 2,316 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

After using an array, is it something to nothing?

MLH
I get the concept of setting an object variable
lilke rstCustomers to Nothing (Set rstCustomers = Nothing)

But what about other variable types that can consume
sizable chunks of memory. For instance, array variables.
Is memory automatically released when the called procedure
utilizing them goes out-a-scope? Do programmers have to
worry about memory leaks that may/might/dunno occur?
Oct 11 '06 #1
6 10167
huh? You only set objects = Nothing. Other variables just get
destroyed when they go out of scope.

Oct 11 '06 #2
MLH wrote:
For instance, array variables.
Is memory automatically released when the called procedure
utilizing them goes out-a-scope?
Not for dynamic arrays. Use:

Erase ArrayName

before ArrayName goes out of scope. Read the help file for Erase and ReDim.
Do programmers have to
worry about memory leaks that may/might/dunno occur?
Yes, but there's only so much you can do about it in VBA. You know to close
objects you open and then set them to Nothing, and now you know you should
erase dynamic arrays, too. That's about it.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200610/1

Oct 12 '06 #3

Granny Spitz via AccessMonster.com wrote:
Not for dynamic arrays. Use:

Erase ArrayName
We can use Erase for dimensioned arrays as well as dynamic arrays,
although this seems not to be documented.

We might use this if we have an array of objects, for example an array
of a specific form in a case where we wanted to open more than one
instance of that form.

Dim ArrayOfSpecificForm(0 To 9) As Form_Employees

Public Sub birth()
Dim z As Long
For z = LBound(ArrayOfSpecificForm) To UBound(ArrayOfSpecificForm)
Set ArrayOfSpecificForm(z) = New Form_Employees
With ArrayOfSpecificForm(z)
.Visible = True
.Caption = "Instance " & z
End With
Next z
End Sub

Public Sub death()
Erase ArrayOfSpecificForm
MsgBox UBound(ArrayOfSpecificForm)
MsgBox ArrayOfSpecificForm(0) Is Nothing
End Sub

Erasing the dimensioned array has the same effect as looping through
the array, closing each form and setting the array element to nothing.
The array still has ten elements after calling Erase, but they are all
nothing. It is reusable, that is the first Sub can be run again.
The MsgBox calls are only to illustrate the nature of the array after
calling Erase.

Note that the Employees from must have a module or the HasModule
property set to true in order to use Form_Employees.

One can experiment with Erase ... as below and beyond:

Sub f()
Dim a(0 To 1) As String
a(0) = "Granny"
a(1) = "Spitz"
Debug.Print Len(a(0))
Debug.Print Len(a(1))
Erase a
Debug.Print Len(a(0))
Debug.Print Len(a(1))
End Sub

Sub g()

Dim a(0 To 1) As Double
a(0) = 5 / 3
a(1) = 12 / 7
Debug.Print a(0)
Debug.Print a(1)
Erase a
Debug.Print a(0)
Debug.Print a(1)

End Sub

Oct 12 '06 #4
Granny Spitz via AccessMonster.com wrote:
MLH wrote:
>>For instance, array variables.
Is memory automatically released when the called procedure
utilizing them goes out-a-scope?


Not for dynamic arrays. Use:

Erase ArrayName

before ArrayName goes out of scope. Read the help file for Erase and ReDim.

>>Do programmers have to
worry about memory leaks that may/might/dunno occur?


Yes, but there's only so much you can do about it in VBA. You know to close
objects you open and then set them to Nothing, and now you know you should
erase dynamic arrays, too. That's about it.
Also, closing Recordsets is really really important to prevent memory leaks.

--
'---------------
'John Mishefske
'---------------
Oct 12 '06 #5
MLH
I thought I'd heard something about
other sources for memory leaks & the
like. Thx. Will look N2 it. Could not
recall Erase ArrayName =gettin' too
old for this stuff, I swear.
Oct 13 '06 #6
"Granny Spitz via AccessMonster.com" <u26473@uwewrote in
news:67a28a69794af@uwe:
MLH wrote:
>Do programmers have to
worry about memory leaks that may/might/dunno occur?

Yes, but there's only so much you can do about it in VBA. You know to
close objects you open and then set them to Nothing, and now you know
you should erase dynamic arrays, too. That's about it.
Yeah, I spend hours evry day worrying about West Nile Virus, Bird 'Flu,
Adolph Harper and Aids, oh, and not closing database objects and
releasing pointers to them.

So far none of these has ever done me the slightest bit of harm. But I
guess it's fashionable to be safe: oh look Mommie, see where it says,
"Rcs.Close, Set Rcs = Nothing." Aren't I a good boy, Mommie? Aren't I?

Have you ever thought about the statement
Set Rcs = Nothing? What is Nothing? And how could anything be equal to
nothing? Huh? Well, upon further review we find this statement simply
sets the value of the object pointer to zero. So what's "Set Rcs =
Nothing" got to do with that?

I prefer this:

1. don't explicitly open dao recordsets ever;
2. don't open ado recordsets very often; limit this to twice a year;
3. don't close anything;
4. don't release anything;
5. when something doesn't work; repair it;
6. don't write 50000 lines of unnecessary code; this will make #5 way
easier.

I know the MVPs and David won't agree with me (those who haven't
demonstrated their tolerance for disagreement by plonking me that is).
So, what more evidence do you want?

--
Lyle Fairfield
Oct 13 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Deano | last post by:
I needed to have a listbox populated by locations which are stored in tblLocations. However I wanted an "All locations" entry to be at the top of the listbox. This is not in the tblLocations. The...
55
by: AnandaSim | last post by:
I just had a google through this NG but have not seen mention of Erik Rucker's blog entry and the new Jet: http://blogs.msdn.com/access/archive/2005/10/05/477549.aspx mentioned by Mike...
8
by: Tweaxor | last post by:
Hey, I was trying to figure out was it possible in C to pass the values in an array from one function to another function. Is the possible in C? ex. y is the array that holds seven values If...
13
by: Bob Day | last post by:
Using vs2003, vb.net I start a thread, giving it a name before start. Code snippet: 'give each thread a unique name (for later identification) Trunk_Thread.Name = "Trunk_0_Thread" ' allow...
11
by: D | last post by:
I have a winforms app that I'm reading some records from a datareader and writing them out to a file like so SqlDataReader dataReader = sqlCommand.ExecuteReader(); TextWriter textWriter = new...
7
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
0
by: bjanaszek | last post by:
I am migrating the reporting functionality of my company's web application from Crystal Reports 9.x to SQL Reporting Services 2000, and I am using the Reporting Services web service to render the...
12
by: xla76 | last post by:
I have a function that returns an array of string values, occasionally the returned array value is 'Nothing' I need to check if the value is nothing before moving on - how can I do this - none of...
1
by: csgirlie | last post by:
I'm trying to store or arrange three sets of two-dimensional data into three 2xN matrices that are stored as NumPy arrays. import os # for file handling functions import numpy as...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.