Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default More efficient memory deallocation

Hello again,

I have code which involves many objects that have references to each other.

This causes large memory leaks since VBA is not able to deaalocate all
memory that has gone out of scope. So, I set all references, etc to NOTHING
when the objects terminate. Problem is there is still a significant memory
leak AND it is quite time consuming.

So does anyone know of a fast way to deallocate memory? The Unload
statement does not seemto help either.

What might be ideal is maybe a windows API function that deallocates memory.
In theory we should be able to point to an address in memory and a size of
the object structure and free that memory. Does anyone have know the details
of we can do something like that?

Any insights would be greatly appreciated.

Thanks,

Chris (ct60)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default More efficient memory deallocation

VBA releases memory when it is appropriate. There are certainly bugs that
cause memory leaks, but I haven't heard of any associated with assigning
variables.

--
Regards,
Tom Ogilvy

"ct60" wrote in message
...
Hello again,

I have code which involves many objects that have references to each
other.

This causes large memory leaks since VBA is not able to deaalocate all
memory that has gone out of scope. So, I set all references, etc to
NOTHING
when the objects terminate. Problem is there is still a significant
memory
leak AND it is quite time consuming.

So does anyone know of a fast way to deallocate memory? The Unload
statement does not seemto help either.

What might be ideal is maybe a windows API function that deallocates
memory.
In theory we should be able to point to an address in memory and a size of
the object structure and free that memory. Does anyone have know the
details
of we can do something like that?

Any insights would be greatly appreciated.

Thanks,

Chris (ct60)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default More efficient memory deallocation

From what I've read, rather than what I know, the consensus seems to be it's
generally un-necessary to explicitly set object references to nothing just
before they would lose scope automatically, and might even do harm if done
in the wrong order. A strong and noteworthy opponent against is Matthew
Curland.

What seems more contentious though is the subject of "circular references",
even as to how the term is defined. From what you've described perhaps you
have those.

There has been a lot of discussion over the years in
microsoft.public.vb.general.discussion

Concerning API's you could look at HeapAlloc & HeapFree, though I doubt they
will help and I wouldn't touch them without fully understanding them.

I trust you are not using the End statement at all. Any automation, if so
are created objects closed/quit before any references to them are
destroyed..

Regards,
Peter T


"ct60" wrote in message
...
Hello again,

I have code which involves many objects that have references to each

other.

This causes large memory leaks since VBA is not able to deaalocate all
memory that has gone out of scope. So, I set all references, etc to

NOTHING
when the objects terminate. Problem is there is still a significant

memory
leak AND it is quite time consuming.

So does anyone know of a fast way to deallocate memory? The Unload
statement does not seemto help either.

What might be ideal is maybe a windows API function that deallocates

memory.
In theory we should be able to point to an address in memory and a size

of
the object structure and free that memory. Does anyone have know the

details
of we can do something like that?

Any insights would be greatly appreciated.

Thanks,

Chris (ct60)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default More efficient memory deallocation

Thanks Guys -

I believe that this problem is fairly well documented.

If you have object A which has a ref to obj B which has a ref to obj C ( and
lets say that obj C also has a ref to obj B), when A goes out of scope - in
theory B and C should also. This does not happen. Watch in the memory usage
of excel in the task manager to see this effect.

Explicit use of the set obj=Nothing before terminating will resolve this
situation to a certain extent. Again, checking the memory usage for larger
programs will show clearly the memory deallocation. Out testing shows,
however, that there is still a fairly significant memory leak and the process
is time consuming.

One would expect that memory deallocation should be a very high speed
process. That being said, one of the advantages of using vba is that the
machine is smart enough to take on memory management issues rather than the
programmer.

And all this works ok until those rare time when we get into highly
sophisticated programs and want to have greater control over memory
management.

I am sure there are ways to get handles to objects in memory and dealloc
them in a high speed pprocess but it is surely a slippery slope. If this
problem is too pronounced then maybe we need lower level languages like C/C++
or perhaps C#.

Thanks again.

Chris

"Peter T" wrote:

From what I've read, rather than what I know, the consensus seems to be it's
generally un-necessary to explicitly set object references to nothing just
before they would lose scope automatically, and might even do harm if done
in the wrong order. A strong and noteworthy opponent against is Matthew
Curland.

What seems more contentious though is the subject of "circular references",
even as to how the term is defined. From what you've described perhaps you
have those.

There has been a lot of discussion over the years in
microsoft.public.vb.general.discussion

Concerning API's you could look at HeapAlloc & HeapFree, though I doubt they
will help and I wouldn't touch them without fully understanding them.

I trust you are not using the End statement at all. Any automation, if so
are created objects closed/quit before any references to them are
destroyed..

Regards,
Peter T


"ct60" wrote in message
...
Hello again,

I have code which involves many objects that have references to each

other.

This causes large memory leaks since VBA is not able to deaalocate all
memory that has gone out of scope. So, I set all references, etc to

NOTHING
when the objects terminate. Problem is there is still a significant

memory
leak AND it is quite time consuming.

So does anyone know of a fast way to deallocate memory? The Unload
statement does not seemto help either.

What might be ideal is maybe a windows API function that deallocates

memory.
In theory we should be able to point to an address in memory and a size

of
the object structure and free that memory. Does anyone have know the

details
of we can do something like that?

Any insights would be greatly appreciated.

Thanks,

Chris (ct60)




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default More efficient memory deallocation

I believe that this problem is fairly well documented.

And highly debated!

In theory although memory may not be released when the reference goes out of
scope while the app is still running, when the code fully terminates VB(A)'s
garbage collection "should" restore. At least that's what some say.

A working example perhaps along the lines of what you describe is argued
here
http://tinyurl.com/vl624

(see thread view post 8 & on)

I suspect memory leak may also be caused by other things besides object
references.

Regards,
Peter T

http://tinyurl.com/vl624
"ct60" wrote in message
...
Thanks Guys -

I believe that this problem is fairly well documented.

If you have object A which has a ref to obj B which has a ref to obj C (

and
lets say that obj C also has a ref to obj B), when A goes out of scope -

in
theory B and C should also. This does not happen. Watch in the memory

usage
of excel in the task manager to see this effect.

Explicit use of the set obj=Nothing before terminating will resolve this
situation to a certain extent. Again, checking the memory usage for

larger
programs will show clearly the memory deallocation. Out testing shows,
however, that there is still a fairly significant memory leak and the

process
is time consuming.

One would expect that memory deallocation should be a very high speed
process. That being said, one of the advantages of using vba is that the
machine is smart enough to take on memory management issues rather than

the
programmer.

And all this works ok until those rare time when we get into highly
sophisticated programs and want to have greater control over memory
management.

I am sure there are ways to get handles to objects in memory and dealloc
them in a high speed pprocess but it is surely a slippery slope. If this
problem is too pronounced then maybe we need lower level languages like

C/C++
or perhaps C#.

Thanks again.

Chris

"Peter T" wrote:

From what I've read, rather than what I know, the consensus seems to be

it's
generally un-necessary to explicitly set object references to nothing

just
before they would lose scope automatically, and might even do harm if

done
in the wrong order. A strong and noteworthy opponent against is Matthew
Curland.

What seems more contentious though is the subject of "circular

references",
even as to how the term is defined. From what you've described perhaps

you
have those.

There has been a lot of discussion over the years in
microsoft.public.vb.general.discussion

Concerning API's you could look at HeapAlloc & HeapFree, though I doubt

they
will help and I wouldn't touch them without fully understanding them.

I trust you are not using the End statement at all. Any automation, if

so
are created objects closed/quit before any references to them are
destroyed..

Regards,
Peter T


"ct60" wrote in message
...
Hello again,

I have code which involves many objects that have references to each

other.

This causes large memory leaks since VBA is not able to deaalocate all
memory that has gone out of scope. So, I set all references, etc to

NOTHING
when the objects terminate. Problem is there is still a significant

memory
leak AND it is quite time consuming.

So does anyone know of a fast way to deallocate memory? The Unload
statement does not seemto help either.

What might be ideal is maybe a windows API function that deallocates

memory.
In theory we should be able to point to an address in memory and a

size
of
the object structure and free that memory. Does anyone have know the

details
of we can do something like that?

Any insights would be greatly appreciated.

Thanks,

Chris (ct60)






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
XL 2007 - Out of Memory - memory leak/bug? PCLIVE Excel Discussion (Misc queries) 0 March 23rd 09 03:31 PM
more efficient VBA? markx Excel Programming 4 August 7th 06 05:41 PM
More efficient way? Steph[_3_] Excel Programming 6 June 23rd 04 09:34 PM
Which is more efficient? Norm[_5_] Excel Programming 3 April 2nd 04 04:24 PM
The instruction at "0x65255ac9" referenced memory at "0x00000008". The memory could not be read. Clikc OK to terminate etc Angus Comber[_2_] Excel Programming 1 November 7th 03 01:18 PM


All times are GMT +1. The time now is 04:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"