Memory Leak... getting frustrated!

I originally started a post here:

https://forum.xojo.com/17048-shell-in-class-method-results-in-memory-leakage

Come to find out, it’s not all green on the new side of the fence after all. I’ve spent nearly an entire day trying to track down a substantial memory leak issue I’m having on Linux. I have attached the portions of my application that are affected by this. Could somebody (who uses Linux or has a test environment for Linux) please review and test this and see if you’re getting the same results. The application simply outputs the amount of virtual memory space it uses on the terminal… THAT’S IT. That itself, using the methods within, are causing a leak. I initially suspected an issue with Shell… then after process of elimination… found that didn’t appear to be it. Then I moved to memoryBlocks. I converted all those to strings (as I was basically using them as such anyhow) and am still getting the same issue. I’m stumped… as I have NO idea what’s causing the issue. Thanks…

myApp.xojo_xml_project

Forgot to mention… when you run it, it displays the memory of the process being occupied (in KB). Note what it starts with, then over the course of 15-20 minutes it starts to increase. There’s nothing I’m doing except passing/manipulating strings and running the shell command.

Hi, I can confirm this.
OpenSUSE 12.3 (x86_64), compiled with Xojo 2014r21.
Virtual and reserved memory use goes up to the hill.

Thanks, Rolf!

FOUND IT! This is a bug in Xojo… the memory leak occurs under the getProcessVsz method:

leaks memory:

return coreSystem.processShell("ps aux | grep " + processName + " | grep -v grep | awk 'NR==1' | awk '{print $5}'", false, false)

However, if I don’t include the ’ + processName + ’ and replace that with the hard-coded value of my application’s name… it doesn’t leak. Combining string values like this is leaking substantial memory. Not sure if this is something just on Linux, if it’s only leaking if combining within the same line as the return statement, etc. Going to run some more tests and find out.

Simplified this… and would like an employee/developer of Xojo to chime in and get their opinion at what may be causing this.

I have a simple Linux console application (have not tested this leak on any other platform). It now has a RUN event, and a myMethod method as follows:

[code]Function Run(args() as String) As Integer

const THREAD_IDLE_INTERVAL = 1

dim a as uInt32

// - keep main thread running
do
a = a + 1
print str(a) + " " + myMethod
app.doEvents(THREAD_IDLE_INTERVAL)
loop

End Function[/code]

[code]Function myMethod() As string

dim a as string
dim s as new shell

a = “myApp”

s.execute(“ps aux | grep " + a + " | grep -v grep | awk ‘NR==1’ | awk ‘{print $5}’”) 'this one leaks substantial memory
's.execute(“ps aux | grep myApp | grep -v grep | awk ‘NR==1’ | awk ‘{print $5}’”) 'this one does not

return trim(s.result)
End Function[/code]

You’ll notice that under the myMethod method, if you use the first s.execute statement and run the application… it’ll jump up in memory usage after about 388 iterations. If you use the second s.execute statement and run the application… it’ll take substantially longer for this to happen (still a leak, but likely related to the shell command). Not sure why the shell command would interpret the two strings differently. Not sure either if this is an issue w/ how strings are conjoined within Xojo, or how the Shell command interprets the constructed string. Possibly an issue w/ how the encoding information is stored within memory? I’ve simplified this the best I could which shows the issue. Not sure how you want me to create a feedback on it, because I’m still not sure what is causing the issue. If Greg or Norman want to pick this up and take care of processing that, that would be great… thanks, guys.

BTW, I forgot to mention… when constructing your application to test with, name it ‘myApp’ or change the name in the myMethod accordingly.

If before the call you create the string by putting the pieces of into an array and use join to create the string or use a single string literal and do:

theStringLiteral.Replace("ProcessName ", ProcessName),

do you still see the leak?

[quote=141551:@Karen Atkocius]If before the call you create the string by putting the pieces of into an array and use join to create the string or use a single string literal and do:

theStringLiteral.Replace("ProcessName ", ProcessName),

do you still see the leak?[/quote]

Single string literals don’t seem to be affected by the leak. Anything else I’ve tried appears to contain the issue. I also converted the string to a memoryBlock and tried the .stringValue function of it. It also had the same issue.