Skip to content

Garbage Collection in Windows Mobile and Low memory conditions

Oct 24, 2010 | 42Gears Team

Garbage collector is a piece of code responsible for allocating and freeing unreferenced objects in a managed application. Garbage collection operation is invoked whenever:

  • the application calls GC.Collect() method
  • CLR cannot allocate memory for an object
  • the application loses focus and goes to the background
  • the system sends WM_HIBERNATE message to the managed application

If a Windows Mobile or Windows CE device does not have sufficient memory to allocate new objects, the system sends WM_HIBERNATE message to inactive applications; first being the longest inactive one. If WM_HIBERNATE handling by the application results in free memory sufficient for the current allocation requirement, the message is not sent to remaining apps. If the required memory is not reclaimed this way, the system starts terminating running applications by first sending them WM_CLOSE message and if required followed by calling TerminateProcess() call on them. This process also stops as soon as sufficient memory is reclaimed.

After the WM_HIBERNATE message is received by the application, a full garbage collection takes place. Its a good idea to dispose as many objects as possible during the handling of hibernate event.

Subscribe for our free newsletter

Thank you! you are successfully subscribed.
newsletter

Exclusive News and Updates on Enterprise Mobility!

* I consent to receive newsletters via email from 42Gears and its Affiliates.
Please agree
* I have reviewed and agreed to 42Gears Privacy Policy and Terms of Use prior to subscribing and understand that I may change my preference or unsubscribe at any time.
Please agree
Please verify captcha
Please enter a valid official email