PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Memory leak? Something not being freed?  (Read 1618 times)

thenewguy

  • Member
  • **
  • Posts: 15
    • View Profile
Memory leak? Something not being freed?
« on: December 14, 2023, 03:13:39 PM »
Hello,
I have a program that I run from the command line, in it, it does a whole bunch of stuff, including generating an XML file, and calling another program to get info for that XML file. I think this called program is the culprit.

It generates a certain number of xml documents and then RUNs the main menu. For some reason my program keeps taking more and more memory the more documents it has to make, and then never releases that memory.

I ran Process Explorer to watch the memory usage, see attachment.
#1 is where my program starts
#2 is where my program gives me an error 31 and i use set_param 'iz' to give it more memory
#3 is where my program is done, and runs our "main menu", but pxplus.exe stays at that amount of memory usage.

When I first launch our software, its sitting at about 8 MB of ram in use.
By the end of generating 300 documents, it's at 356.5 MB.

It goes back to the menu and there's no indication that anything is wrong.
No open channels to anything, no variables in the dump that are huge...

My current hunch is that the called program i mentioned dims a half dozen 999,999 arrays and somehow those are getting stuck in memory?
The program does an EXIT to return to the calling program, and the dims are no longer in the dump at that point. But something tells me that's what's happening?

I know I left a lot of detail out, I'm happy to provide more info.

Also, if anyone has any memory debugging tools, like "show me what in pxplus is taking all this RAM", I'd love that!
« Last Edit: December 14, 2023, 03:49:41 PM by thenewguy »

Loren Doornek

  • Gold Member
  • ****
  • Posts: 85
    • View Profile
Re: Memory leak? Something not being freed?
« Reply #1 on: December 14, 2023, 03:54:23 PM »
Are you using any LOCAL commands to localize variables?  Or maybe a LOCAL DIM of the arrays?  I've seen big memory leaks when a variable is localized multiple times without ever exiting the stack/subroutine that localized the variable.

thenewguy

  • Member
  • **
  • Posts: 15
    • View Profile
Re: Memory leak? Something not being freed?
« Reply #2 on: December 14, 2023, 04:01:43 PM »
Neither program uses the LOCAL command even once!  :(

thenewguy

  • Member
  • **
  • Posts: 15
    • View Profile
Re: Memory leak? Something not being freed?
« Reply #3 on: December 14, 2023, 04:10:32 PM »
Cancel this question. I wasn't dropping the XML objects.  :o

Although, I'm still curious if there are any tools to monitor or analyze memory usage within pxplus. Anyone know of anything?
« Last Edit: December 15, 2023, 09:03:26 AM by thenewguy »

Mike King

  • Diamond Member
  • *****
  • Posts: 3818
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Memory leak? Something not being freed?
« Reply #4 on: December 15, 2023, 12:32:46 PM »
To see what you have open, on Windows click on the icon in the upper left (or press ALT-SPACE) then select About PxPlus.  From there select the info button.  This will show you all files, windows, controls and object you are using.

Also, to avoid unwanted left over objects, always consider adding a FOR clause when creating an object with the NEW function which will allow you set dependencies on the new object which will allow for automatic deletion.  For example if the object is only used in a subroutine while its active you could add FOR PROGRAM.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com