1. Roland Smith
  2. PowerBuilder
  3. Friday, 15 December 2023 17:36 PM UTC

I have a PB 2022 app that uses multi-threading (SharedObject functions) to receive messages via Winsock and update a SQL Anywhere database.

The app is running on a server that doesn't have a lot of memory. I'm wondering if there is a way to tell the memory manager to release unused memory.

The main thread calls GarbageCollect every 15 seconds but that just releases any unused objects.

Benjamin Gaesslein Accepted Answer Pending Moderation
  1. Monday, 18 December 2023 10:38 AM UTC
  2. PowerBuilder
  3. # 1

Hi Roland,

I think you'll need to analyze where your "excessive allocated memory" comes from. If you're doing db operations I presume you're passing datastore blobs between threads? I'd say this is the most likely culprit. Make sure you're always passing those by reference and assign an empty blob variable to them once you don't need them anymore.

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 18 December 2023 05:07 AM UTC
  2. PowerBuilder
  3. # 2

Not sure if this would be possible in your app, but minimizing and restoring the frame window or the main app window, would release memory.

 

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Friday, 15 December 2023 19:00 PM UTC
  2. PowerBuilder
  3. # 3

Hi, Roland -

Some points you probably have already handled but, nonetheless:

Make sure that a SharedObjectUnregister() call is made for every object where a SharedObjectRegister() was performed.

GarbageCollect() will only reclaim memory used by an object when there are no valid references to the object, so manage the scope of the object reference vars and destroy them or invalidate (SetNull) them when they are no longer needed.

Consider using the Restart() PowerScript function on a regular interval when the app becomes idle AND has performed some arbitrary amount of work/activity.

Best regards, John

Comment
  1. Roland Smith
  2. Monday, 18 December 2023 05:03 AM UTC
The app is busy pretty much all day so a restart would result in connection errors for the sending apps. I was hoping there was an undocumented function of one of the runtime libraries that would tell it to release unused memory.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Monday, 18 December 2023 15:37 PM UTC
Hi Roland;

Also, try not to use Auto Instantiated objects. Always do your own Create's & Destroy's.

Regards ... Chris
  1. Helpful
  1. Chris Pollach @Appeon
  2. Monday, 18 December 2023 16:06 PM UTC
Also, make sure that you release all DWO memory & object itself at end of use ....

DC/DS.Reset()

DC/DS.dataobject = ""

Destroy DS
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.