Skip to main content
Home
for DLMS smart meters
Open source solutions for DLMS smart metering

Main navigation

  • Home
  • Products
  • About us
  • Open Source
  • Community
  • Forum
  • Downloads
User account menu
  • Log in

Breadcrumb

  1. Home
  2. Facing Error "not Enough Memory Available" Even Though Enough Heap Memory Available

Facing error "not enough memory available" even though enough heap memory available

By Suketa , 21 October, 2024
Forums
DLMSDirector

Hello,

I am using controller and follow below code to read IP data,

i16ret = cosem_init(&gMRICDataObj.base, DLMS_OBJECT_TYPE_DATA,
MR_INVOCATION_COUNTER_OBISCODE);

i16ret = cosem_init(&gInstantaneousProfileGenericObj.base,
DLMS_OBJECT_TYPE_PROFILE_GENERIC,
INSTANTANEOUS_PROFILE_OBISCODE);
cl_init(&cCon.settings, LOGICALNAMEREFERENCING, CLIENTADDRESS_PC,
SERVERADDRESS, DLMS_AUTHENTICATION_NONE, NULL,
DLMS_INTERFACE_TYPE_WRAPPER);
com_initializeConnection(&cCon);

com_read(&cCon, &gMRICDataObj.base,2);

com_disconnect(&cCon);

cl_init(&cCon.settings, LOGICALNAMEREFERENCING, CLIENTADDRESS_MR,
SERVERADDRESS, DLMS_AUTHENTICATION_LOW, HPL_MR_PASSWORD,
DLMS_INTERFACE_TYPE_WRAPPER);

cCon.settings.cipher.invocationCounter = (gMRICDataObj.value.ulVal+ 1);
cCon.settings.cipher.security = DLMS_SECURITY_ENCRYPTION;

com_initializeConnection(&cCon);

com_read(&cCon,&gInstantaneousProfileGenericObj.base,3);

cl_clear(&cCon.settings);
com_disconnect(&cCon);

- This code added in loop that repeat at every 1sec
- Facing error "not enough memory" in second iteration
- If I remove com_disconnect and connection initialization before MR as below, it read proper IP data for 617 iterations, after 617 iterations get same memory error.

i16ret = cosem_init(&gMRICDataObj.base, DLMS_OBJECT_TYPE_DATA,
MR_INVOCATION_COUNTER_OBISCODE);

i16ret = cosem_init(&gInstantaneousProfileGenericObj.base,
DLMS_OBJECT_TYPE_PROFILE_GENERIC,
INSTANTANEOUS_PROFILE_OBISCODE);
cl_init(&cCon.settings, LOGICALNAMEREFERENCING, CLIENTADDRESS_PC,
SERVERADDRESS, DLMS_AUTHENTICATION_NONE, NULL,
DLMS_INTERFACE_TYPE_WRAPPER);
com_initializeConnection(&cCon);

com_read(&cCon, &gMRICDataObj.base,2);

cl_init(&cCon.settings, LOGICALNAMEREFERENCING, CLIENTADDRESS_MR,
SERVERADDRESS, DLMS_AUTHENTICATION_LOW, HPL_MR_PASSWORD,
DLMS_INTERFACE_TYPE_WRAPPER);

cCon.settings.cipher.invocationCounter = (gMRICDataObj.value.ulVal+ 1);
cCon.settings.cipher.security = DLMS_SECURITY_ENCRYPTION;

com_read(&cCon,&gInstantaneousProfileGenericObj.base,3);
cl_clear(&cCon.settings);

Please suggest me correct sequence

Thanks,
Suketa

Suketa

1 year 7 months ago

Can you please provide an…

Can you please provide an update?

Profile picture for user Kurumi

Kurumi

1 year 7 months ago

Hi, You need to clear the…

Hi,

You need to clear the read objects after use.
Something like this:

com_read(&cCon,&gInstantaneousProfileGenericObj.base,3);
obj_clear(BASE(gInstantaneousProfileGenericObj));

BR,
Mikko

Suketa

1 year 7 months ago

Hi, I already checked by…

Hi,

I already checked by using obj_clear for MR and instantaneous profile object and cl_clear before disconnecting as below,

16ret = cosem_init(&gMRICDataObj.base, DLMS_OBJECT_TYPE_DATA,
MR_INVOCATION_COUNTER_OBISCODE);

i16ret = cosem_init(&gInstantaneousProfileGenericObj.base,
DLMS_OBJECT_TYPE_PROFILE_GENERIC,
INSTANTANEOUS_PROFILE_OBISCODE);
cl_init(&cCon.settings, LOGICALNAMEREFERENCING, CLIENTADDRESS_PC,
SERVERADDRESS, DLMS_AUTHENTICATION_NONE, NULL,
DLMS_INTERFACE_TYPE_WRAPPER);
com_initializeConnection(&cCon);

com_read(&cCon, &gMRICDataObj.base,2);

com_disconnect(&cCon);

cl_init(&cCon.settings, LOGICALNAMEREFERENCING, CLIENTADDRESS_MR,
SERVERADDRESS, DLMS_AUTHENTICATION_LOW, HPL_MR_PASSWORD,
DLMS_INTERFACE_TYPE_WRAPPER);

cCon.settings.cipher.invocationCounter = (gMRICDataObj.value.ulVal+ 1);
cCon.settings.cipher.security = DLMS_SECURITY_ENCRYPTION;

com_initializeConnection(&cCon);

com_read(&cCon,&gInstantaneousProfileGenericObj.base,3);

obj_clear(&gMRICDataObj.base);
obj_clear(&gInstantaneousProfileGenericObj.base);
obj_clearProfileGenericBuffer(&gInstantaneousProfileGenericObj.buffer);
obj_clearProfileGenericCaptureObjects(&gInstantaneousProfileGenericObj.captureObjects);
cl_clear(&cCon.settings);
com_disconnect(&cCon);

also check that heap memory does not increase after Ip read operation.

I have enough heap memory but still gate error as "not enough memory"

Please check if anything is missing because of that I am facing this error.

Thanks,
Suketa

Profile picture for user Kurumi

Kurumi

1 year 7 months ago

Hi Suketa, Is "not enough…

Hi Suketa,

Is "not enough memory" actually the "Not enough memory available." that the client returns and your app is not crash for lack of heap?

If that is the reason, the data from the meter reply is missing.

Can you add the hex string from the last meter error reply, so I can check what the meter returns and what might cause this?

BR,
Mikko

Suketa

1 year 7 months ago

Hi, Need to send log file…

Hi,

Need to send log file.

can you tell me how I can attach log file here?

Thanks,
Suketa

Profile picture for user Kurumi

Kurumi

1 year 7 months ago

Hi, The easiest way is to…

Hi,

The easiest way is to share it using https://filebin.net
Just add the generated URL to here.

BR,
Mikko

Suketa

1 year 7 months ago

Hi, Thanks for reply. Here I…

Hi,

Thanks for reply.
Here I send URI for my logs.
Logs contain Hex print, other require logs and iteration count.
After 7 successful iteration facing same issue in 8th one.

URI: https://filebin.net/dnpej4xulasrm6fl

Thanks,
Suketa

Profile picture for user Kurumi

Kurumi

1 year 7 months ago

Hi, I also need the block…

Hi,

I also need the block cipher and authentication keys to decrypt this.

BR,
Mikko

Suketa

1 year 7 months ago

Hi, Please find block cipher…

Hi,

Please find block cipher and authentication key below,

Block Cipher Key: 2222222222222222
Authentication Key: 2222222222222222

Thanks,
Suketa

Profile picture for user Kurumi

Kurumi

1 year 6 months ago

Hi, You establish the…

Hi,

You establish the connection without authentication and read the invocation counter.
Then you establish the secured connection and read the association view, but you don't release the connection. Check why!

Next you establish the connection without authentication and read the invocation counter and release the connection after that.

I believe that you don't cleat the read association view objects and that causes the heap to run out.

BR,
Mikko

Suketa

1 year 6 months ago

Hi, I read invocation…

Hi,

I read invocation counter using PC so I think authentication is not requiring.

if I disconnect after read association view, same issue happened.

also, I clear the read association view object after read. you can check term "sMACStatistics.heap.uordblks" in my logs which i sent you. this term indicated used heap. and term "sMACStatistics.heap.arena" that indicate available heap.

you can see that heap is not increasing at that much level that cause problem and enough free heap available when this issue produced

Please tell me if I am missing anything in flow.

Thanks,
Suketa

Profile picture for user Kurumi

Kurumi

1 year 6 months ago

Hi, You can read the…

Hi,

You can read the invocation counter without authentication. I was describing the steps that you made. Missing disconnect might cause problems with some meters.

Is not enough memory available error raised from the debugger or is this an error that DLMS framework returns?

BR,
Mikko

Suketa

1 year 6 months ago

Hi, I checked after adding…

Hi,

I have checked after adding disconnect, same issue generated.

This error given by DLMS lib when try to establish secured connection.

Please check below logs,

DLMS Tx Data = 00 01 00 10 00 01 00 1F 60 1D A1 09 06 07 60 85 74 05 08 01 01 BE 10 04 0E 01 00 00 00 06 5F 1F 04 00 40 1E 1D FF FF
DLMS Rx Data = 00 01 00 01 00 10 00 2B 61 29 A1 09 06 07 60 85 74 05 08 01 01 A2 03 02 01 00 A3 05 A1 03 02 01 00 BE 10 04 0E 08 00 06 5F 1F 04 00 00 00 10 02 26 00 07

DLMS Tx Data = 00 01 00 10 00 01 00 0D C0 01 C1 00 01 00 00 2B 01 02 FF 02 00
DLMS Rx Data = 00 01 00 01 00 10 00 09 C4 01 C1 00 06 00 00 00 00

Disconnect PC connection
DLMS Tx Data = 00 01 00 10 00 01 00 02 62 00
DLMS Rx Data = 00 01 00 01 00 10 00 05 63 03 80 01 00

com_initializeConnection
AARQRequest failed Not enough memory available.

Fail to connect with meter
DLMS Tx Data = 00 01 00 20 00 01 00 14 C8 12 20 00 00 00 01 BC 00 39 03 99 95 03 AA 8F F7 C1 85 76
DLMS Rx Data =
ReadObject failed ProfileGeneric 1.0.94.91.0.255:3 Access Error : Device reports a hardware fault.

Thanks,
Suketa

Profile picture for user Kurumi

Kurumi

1 year 6 months ago

Hi, You can connect to the…

Hi,

You can connect to the meter and read the invocation counter and then close the connection.

AARQ and AARE messages are missing from your log.

Check if this error comes from cl_aarqRequest or cl_parseAAREResponse.

If it's coming from cl_parseAAREResponse, the meter returns invalid data. Sometimes you need to wait a while before establishing a new connection.

BR,
Mikko

Suketa

1 year 6 months ago

Hi, I observed that…

Hi,

I observed that sometimes this error is coming from,

cl_aarqRequest -> bb_capacity , when try to establish secure connection.

sometimes this issue observed when trying to read IP data

Thanks,
Suketa

Profile picture for user Kurumi

Kurumi

1 year 6 months ago

Hi, I believe that you are…

Hi,

I believe that you are not releasing buffer or capture objects after reading Instant Profile, which is causing this.

BR,
Mikko

Suketa

1 year 6 months ago

Hi, As you can see in my…

Hi,

As you can see in my code that I previously shared with you, I clear all capture objects.

I also shared logs with you that contains log related to heap memory. you can see that no heap memory increased after IP read.

Thanks,
Suketa

Suketa

1 year 6 months ago

Hi, I attached my code at…

Hi,

I attached my code at below link.

Please verify if any step is missing.

https://filebin.net/mj9bsqufjyb2exq0

Thanks,
Suketa

Profile picture for user Kurumi

Kurumi

1 year 6 months ago

HI Suketa, Only thing that I…

HI Suketa,

Only thing that I found is call you don't call cl_clear.

cl_clear(&cCon.settings);
cl_init(&cCon.settings, LOGICALNAMEREFERENCING, CLIENTADDRESS_MR,
SERVERADDRESS, DLMS_AUTHENTICATION_LOW, MR_PASSWORD,
DLMS_INTERFACE_TYPE_WRAPPER);

Make sure that you don't allocate memory e.g. in the com_read method that you don't release.

BR,
Mikko

Suketa

1 year 6 months ago

Hi Mikko, I am facing same…

Hi Mikko,

I am facing same issue after this change also.

Thanks,
Suketa

Profile picture for user Kurumi

Kurumi

1 year 6 months ago

Hi Suketa, Your code looks…

Hi Suketa,

Your code looks good, so make sure that you donät allocate the memory somewhere you don't release.

BR,
Mikko

  • Create new account
  • Reset your password

Hire Us!

Latest Releases

  • Tue, 06/09/2026 - 11:16
    gurux.dlms.java 4.0.95
  • Tue, 06/09/2026 - 10:03
    Gurux.DLMS.Python 1.0.199
  • Mon, 06/08/2026 - 13:39
    gurux.dlms.cpp 9.0.2606.0801
  • Mon, 06/01/2026 - 10:15
    gurux.dlms.cpp 9.0.2606.0101
  • Thu, 05/28/2026 - 16:06
    gurux.dlms.java 4.0.94

New forum topics

  • Error reading L&G Meter
  • Pass a TCP Client to GXNet
  • Australian EDMI Mk10D (Essential Energy area)
  • Strange mix of data notificiation vs get response
  • DLMS Connection
More
RSS feed
Privacy FAQ GXDN Issues Contact
Follow Gurux on Twitter Follow Gurux on Linkedin