Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
tyler_tu
Posts: 26
Registered: ‎06-17-2013
My Device: Z10
My Carrier: Bell

MessageService.message memory leak

[ Edited ]

Hello,

 

I have a simple listener to receive SMS events and everything worked fine except that there was a 200~400KBytes memory usage increment upon receiving a SMS or PIN event and didn't release.  Receiving more events won't use more memory, but it also didn't reduce the memory usage as well.

 

Here is the code:

 

SMSMonitor::smileyfrustrated:MSMonitor(QObject *parent) : QObject(parent) {

     m_messageService = newMessageService(this);

 

     connect(m_messageService, SIGNAL(messageAdded(bb::smileytongue:im::account::AccountKey, bb::smileytongue:im::message::ConversationKey, bb::smileytongue:im::message::MessageKey)), SLOT(onMessageAdded(bb::smileytongue:im::account::AccountKey, bb::smileytongue:im::message::ConversationKey, bb::smileytongue:im::message::MessageKey)));

}

 

void SMSMonitor::smileysurprised:nMessageAdded(const bb::smileytongue:im::account::AccountKey &accountKey, const bb::smileytongue:im::message::ConversationKey &conversationKey, const bb::smileytongue:im::message::MessageKey &messageKey) {

 

    Message aMessage = m_messageService->message(smsAccount.id(), messageKey);

   ...

 }

 

I did some experiment to narrow down the problem, it is due to this single line of code

    Message aMessage = m_messageService->message(smsAccount.id(), messageKey);

 

The memory was not released after the program goes out of the scope.  This is a long-running headless app, the memory usage is very critial for us due to the 3MByte limit.

 

Thanks,

 

Tyler

 

Please use plain text.
Developer
ryansweny
Posts: 64
Registered: ‎07-15-2008
My Device: Z10
My Carrier: Rogers

Re: MessageService.message memory leak

I can confirm this too.. receiving one sms bumps up our heap usage from 1075k to 1410k and it never goes back down. In theory we are still well under the 3MB limit but we have had some users complain that it "stops working" after a while which is suspicious.

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: MessageService.message memory leak

Does the memory usage by the SMS listener continue to rise? Or does the increase only happen once?

 

With using SMS, or any PIM services, there could be a cache occurring in memory that would not be unexpected.

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
Contributor
tyler_tu
Posts: 26
Registered: ‎06-17-2013
My Device: Z10
My Carrier: Bell

Re: MessageService.message memory leak

[ Edited ]

The memory usage won't continue rise when receiving more SMS events.  It only increased 400K when receiving the first SMS and keep at this level and never went back down.

 

If there is a cache in the SMS/PIN service, we expect this part of memory usage not accounted in the 3M limit, otherwise the memory space left for our own implementation is too small.

 

Thanks,

 

Tyler

Please use plain text.
BlackBerry Development Advisor (Retired)
gbeukeboom
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: MessageService.message memory leak


tyler_tu wrote: 

If there is a cache in the SMS/PIN service, we expect this part of memory usage not accounted in the 3M limit, otherwise the memory space left for our own implementation is too small.


Unfortunately it may not be that easy of a situation, there's no way to weed out heap based on which API created it to determine what should [not] count toward the 3MB limit.

 

What other services is your app running to account for the 3MB? And how much is needed in total currently?

 

 

Garett
@garettBeuk
--
Goodbye everybody!
Please use plain text.
Contributor
tyler_tu
Posts: 26
Registered: ‎06-17-2013
My Device: Z10
My Carrier: Bell

Re: MessageService.message memory leak

[ Edited ]

Hi Garett,

 

Thanks for the reply.

 

I understand it is hard to seperate the memory usage by the api from the 3M limit, is there any option to disable the CACHE feature from SMS/PIN messageServie?

 

I am not sure what services ryansweny's app running.  For our app, we need to include cascades lib (CONFIG += cascades in .pro file) due to some api calls, such as QtSql.  That is 300K extra memeory usage compare to the one without cascades option.

 

 The app listens to the SMS, PIN, CALL. And It has upload scheduler to take care of the communication between client and remote server via network.  We also need sql database and compression function. Most of tasks such as database access and compression only use memory when it needs.  But if the heap usage keeps staying at a high level and not release, when we need to run those functions, the peak of the usage will over the 3M limit.

 

In my testing, I found some api calls such as qt compress starts throws errors of memory alloc when the total heap usage reaches to 2.5M, this might related with the app "Stops working" issue ryansweny mentioned. 

 

Thanks,

 

Tyler

Please use plain text.
Developer
pfluger
Posts: 100
Registered: ‎02-10-2009
My Device: Q10, Z10
My Carrier: T-Mobile

Re: MessageService.message memory leak

We are seeing this problem, too. 

 

What makes this really bad is that the 400KB seems to be per account. So if the device has two e-mail accounts plus SMS, after you receive messages on all three accounts you have 1.2MB gone. 

 

Add some extra system services that usually like to eat several 100KB each, too, and it is nearly impossible to stay under 3MB.

Please use plain text.