![]() |
Array Question
I use several large array's in a sub routine. Do I need to clear these arrays
in some form before leaving the routine? Thank you |
Array Question
If they are declared as local to the routine, garbage collection should sort
them out. -- HTH Bob Phillips (replace somewhere in email address with gmail if mailing direct) "Sandy" wrote in message ... I use several large array's in a sub routine. Do I need to clear these arrays in some form before leaving the routine? Thank you |
Array Question
Like any other "local" variable, they will be released automatically when
they go out of scope (you leave/end the procedure). -- Regards, Tom Ogilvy "Sandy" wrote: I use several large array's in a sub routine. Do I need to clear these arrays in some form before leaving the routine? Thank you |
Array Question
I know prior versions of Office had VBA Project limits of about 64MB. For
the most part, when it comes to arrays, it can get to be very costly as I would look at 3 things: The type of data the arrays are declared. Variant Data Type takes 22 bytes per element and string data types are multiplied by the number of characters in each element. If the number of characters in the element is 0, assume it's 1 instead for the size purpose. Number of Dimensions Number of elements for each dimension What is the total size of the array? Multiply by the number of elements of each dimension, then multiply that by the number of bytes it takes for the data type that the array is declared as, and that gives you the total size in bytes of the array. Do you need to clear these arrays? Well that's a depend question. In general, it would be good programming practice to clean these up when the program no longer need to rely on these arrays. However, to answer this question, we need to look at the scope that the array variable is at. If the array is at the module level (not within a Sub or Function procedure), then it would need to be cleaned up or at least understand the risks of not having this cleaned up as it remains open for as long as it's not cleaned up. If the array is a procedure level (within a Sub or Function procedure), then it wouldn't necessarily need to be cleaned up, but I have found certain cases where objects seems to get left out there in the RAM and no longer attached to anything, which is what cases memory leakage, so to prevent this sort of issue, one needs to clean things up. If the scope part works as expected, it would clean itself up when the procedure is ended, but I have found cases where this isn't working properly, thus one of the big types of reasons why I don't use the MS Query tool as it is a major memory leakage issue when using ADO coding via the MS Query tool. -- Ronald R. Dodge, Jr. Production Statistician/Programmer Master MOUS 2000 "Sandy" wrote in message ... I use several large array's in a sub routine. Do I need to clear these arrays in some form before leaving the routine? Thank you |
Array Question
If the array is at the module level (not within a Sub or Function
procedure), then it would need to be cleaned up guess you only left out how to clean it up. For a fixed - size array such as you descibe as module level. Public MyArray(1 to 60000, 1 to 256) as Variant how would you clean that up? Sub ABC() if some condition then ' code to clean up array from ' Ronald goes he - don't use Erase please else for i = 1 to 60000 for j = 1 to 256 myarray(i,j) = rnd()*i*j next next End if end sub -- Regards, Tom Ogilvy "Ronald Dodge" wrote: I know prior versions of Office had VBA Project limits of about 64MB. For the most part, when it comes to arrays, it can get to be very costly as I would look at 3 things: The type of data the arrays are declared. Variant Data Type takes 22 bytes per element and string data types are multiplied by the number of characters in each element. If the number of characters in the element is 0, assume it's 1 instead for the size purpose. Number of Dimensions Number of elements for each dimension What is the total size of the array? Multiply by the number of elements of each dimension, then multiply that by the number of bytes it takes for the data type that the array is declared as, and that gives you the total size in bytes of the array. Do you need to clear these arrays? Well that's a depend question. In general, it would be good programming practice to clean these up when the program no longer need to rely on these arrays. However, to answer this question, we need to look at the scope that the array variable is at. If the array is at the module level (not within a Sub or Function procedure), then it would need to be cleaned up or at least understand the risks of not having this cleaned up as it remains open for as long as it's not cleaned up. If the array is a procedure level (within a Sub or Function procedure), then it wouldn't necessarily need to be cleaned up, but I have found certain cases where objects seems to get left out there in the RAM and no longer attached to anything, which is what cases memory leakage, so to prevent this sort of issue, one needs to clean things up. If the scope part works as expected, it would clean itself up when the procedure is ended, but I have found cases where this isn't working properly, thus one of the big types of reasons why I don't use the MS Query tool as it is a major memory leakage issue when using ADO coding via the MS Query tool. -- Ronald R. Dodge, Jr. Production Statistician/Programmer Master MOUS 2000 "Sandy" wrote in message ... I use several large array's in a sub routine. Do I need to clear these arrays in some form before leaving the routine? Thank you |
All times are GMT +1. The time now is 01:32 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com