Fez Spider - How to read memory usage at runtime, HTTPS memory leak

I know that we can monitor the memory usage when debugging by using Debug.GC(). But is there a way the program itself can check how much memory is left, and act accordingly?

The reason for this is because the HTTPS calls in my program is leaking memory, and I want it to reboot whenever the amount of memory left dropped below a certain threshold.

Btw, is there any workaround to the memory leak (https://netmf.codeplex.com/workitem/2005), of EMX package 4.2 (https://www.ghielectronics.com/support/netmf/sdk/8/netmf-and-gadgeteer-package-2013-r3), because rebooting is really just an awkward temporary fix.

Thanks for all your help in advance !

Didn’t know the first link would be hidden.

The HTTPS memory leak is listed under the known issues on the package webpage, with description “There is a memory leak when using SSL. This affects HTTPs classes that wrap SslStream. See https://netmf.codeplex.com/workitem/2005 for more information.”

If all you are interested in is the currently available memory, then Debug.GC(false) can be used, it is not limited to while debugging the application.

@ taylorza -

Thanks for your reply!

I understand that Debug.GC() works whether it’s debugging or not, but how could the program read from Debug.GC() to know that it’s already at a low memory level? because I assume that Debug.GC() is just printing the data out.

@ lty20785 - Debug.GC() is a function and returns the amount of memory available so you could probably do something like the following

if (Debug.GC(false) < someThreshold)

Debug.GC has a return value.
It returns the free memory.
But keep in mind that the largest block of memory (in a single array) is about 76kByte.
Also if it returns, lets say1 MByte, you still might fail to allocate 5kByte (just an example) because of fragmentation.

The largest single allocation is 760KB, unless you use LargeBuffer class.

@ taylorza -

I really should’ve read the documentation more carefully… as I thought Debug.GC returns void.

Thanks again for your help !

@ Reinhard Ostermeier -

Thank you for the friendly reminders! I’ll certainly keep them in mind when checking the memory.

@ lty20785 - It is a pleasure, and the good thing is now you links are showing… Welcome to the community and happy new year.

@ taylorza - thank you for the correction.
@ lty20785 - you’re welcome- have fun

@ taylorza -

Yeah… I’ve now got enough exp points for my links to show.

Happy new year too and all the best for you in 2014!

@ Reinhard Ostermeier - No problem, I keep forgetting the number my self, I just coincidentally been doing something with LargeBuffer recently so it is fresh in my memory.

@ Reinhard Ostermeier -

I’ll try to have fun but the memory leak is just :wall:

Anyways, happy new year and all the best for you in 2014!