pressing the "reset" button and freeing memory

  • Thread starter Thread starter Elie W
  • Start date Start date
E

Elie W

I am a bit of a newbie so maybe there is a simple answer to this question.

I have been using some code that uses LocalAlloc() from the windows API
to allocate memomry on the heap (right?).

In order to make sure that I was freeing the memory correctly I was
requesting a large amount of memory so that I could monitor it in the
task manager.
lpSelPath = LocalAlloc(LPTR, 100000000)

I can usually free the memory without a problem. I realized though that
if I click the reset button on the debug toolbar, before the memory is
released in the code, the memory is not released. Is this correct
behavior? Is it b/c the reset only frees the local stack and not the heap?

Is there a way to free the code (aside from shutting down excel) to free
the memmory?

Thanks,
Elie.
 
I haven't studied up on my pointers for a while, but that does seem lik
it should happen. What you are seeing is correct IMO. I believe th
memory is falling under excel control to the OS and when the OS look
at it it doesn't free it because Excel is under control of it. Bu
excel doesn't have any pointers pointing to it (since the progra
ended) so it can't use it. I am assuming that excel doesnt have an
type of garbage collection built into it to catch the case of n
pointers pointing to memory and freeing it. If you would like yo
could try running a ram optimizer (I use FreeRAM XP pro) that does
pretty good job of finding unreferenced memory and freeing it, it is
background app so you shouldn't have to shut down excel. Do delete i
back in code you would need to save the pointer in the workboo
somewhere and then try to reference it when you start the program bac
up. I wouldn't recommend that though. Hope that is correct and help
a little.

Keith
www.kjtfs.co
 
KJTFS said:
I haven't studied up on my pointers for a while, but that does seem like
it should happen. What you are seeing is correct IMO. I believe the
memory is falling under excel control to the OS and when the OS looks
at it it doesn't free it because Excel is under control of it. But
excel doesn't have any pointers pointing to it (since the program
ended) so it can't use it. I am assuming that excel doesnt have any
type of garbage collection built into it to catch the case of no
pointers pointing to memory and freeing it.

I think you got it. It must allocate it to Excel's namespace. And that
is just it, unless you get rid of it manually there is no way to get rid
of it.

I guess on another level, what I am asking is if there is anyway to have
some code execute when the reset button is pushed.

Thanks,
Elie.
 
That I am not sure on, I am pretty sure in development IDE's like visua
studio. NET you can create Macro's to run when you do things like clic
buttons and whatnot, I am not sure if that is possible to do in VB
IDE, might be worth looking into. But if you could hook some functio
to look for dynamically allocated memory and free it I guess that woul
work but that is above my knowledge without some serious research.
Hopefully someone else can chime in.

Keith
www.kjtfs.co
 
Back
Top