Allowing Large Memory Allocation

This section describes how an application can request for free memory from OOM Monitor for large amount of RAM allocation.

An application can allocate RAM without seeking the permission from the OOM Monitor if the amount of RAM is not over KOomMaxAllocationWithoutPermission limit.

If an application needs to allocate more RAM than allocated by KOomMaxAllocationWithoutPermission , it must request the OOM Monitor using the ROomMonitorSession::RequestFreeMemory() method.

An application can request for free RAM either synchronously or asynchronously.

  1. Create an OOM Monitor session
            ROomMonitorSession ioomMonitorSession;
    CleanUpClosePushL(ioomMonitorSession);
    User::LeaveIfError(ioomMonitorSession.Connect());
           
  2. Request for free memory can be done in two ways:

The OOM Monitor allows the client application to allocate memory, if the free RAM level is above the LOW_RAM_THRESHOLD value.

If the free RAM level is below the LOW_RAM_THRESHOLD value, the OOM Monitor releases RAM using ROomMonitorSession::RequestFreeMemory() method. This method returns the following values:
  • Requested amount of RAM is available then aStatus is set to KErrNone .

  • Requested amount of RAM is not available then aStatus is set to KErrNoMemory .