Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 23:53, 19 August 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Compressing heap memory on Symbian

From Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia N95
Keywords: Heap
Created: User:Nokia Developer KB (03 Apr 2009)
Last edited: hamishwillee (19 Aug 2012)



The CompressAllHeaps() method reclaims any available pages at the top of each user heap. It does not attempt heap defragmentation and ignores locked heaps, so it is very efficient.


The amount of memory given back to the system following a call to User::CompressAllHeaps can vary a lot, is quite unpredictable, and does not work in some cases.

Check the code snippet where memory allocation (User::Alloc() method) has been done and immediately compressed using the CompressAllHeaps and Heap().Compress() methods. The logs indicate that the free RAM size has increased. This function works fine only when there is free RAM on top of each user heap.


The following code snippet shows how to use the CompressAllHeaps functionality.

  //sample code
TInt retval;
TInt retval1;
TInt ibeforeFreeRAM;
TInt iafterFreeRAM;
TInt iafterFreeRAMCompress;
HAL::Get(HAL::EMemoryRAMFree, ibeforeFreeRAM);
TBuf<50> temp;
TBuf<50> temp1;
TBuf<50> temp2;
DebugLog(_L("ibeforeFreeRAM "));
retval=User::CompressAllHeaps(); //using CompressAllHeaps method
HAL::Get(HAL::EMemoryRAMFree, iafterFreeRAM);
User::Heap().Compress(); //using Heap Compress method
HAL::Get(HAL::EMemoryRAMFree, iafterFreeRAMCompress);
DebugLog(_L("iafterFreeRAM : Compress"));
Output sample:
ibeforeFreeRAM 23875584
iafterFreeRAM 24113152
iafterFreeRAM : Compress 24113152

Related articles

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

This page was last modified on 19 August 2012, at 23:53.
51 page views in the last 30 days.