Posting here before opening a bug request in case I missed something.
I have several web apps running 24/7 used only with their handleurl events as API. I have a memory leak with HandleURL in a Web project in Xojo 2023r4.
To test:
- Create a new web application
- In the HandleURL event, place the following code:
'use static to have the entire code in one page without any dependencies to properties
static NumRequests as integer
static initialObjectCount as integer
Static initialMemoryUsed as integer
'initialize
if initialObjectCount = 0 then initialObjectCount = Runtime.ObjectCount
if initialMemoryUsed = 0 then initialMemoryUsed = Runtime.MemoryUsed
'increment number of requests
NumRequests = NumRequests + 1
'build the page
var thePage as string
thePage = "<html><head><title>test</title></head><body>"
thePage = thePage + "Num requests : " + NumRequests.ToString + "<br>"
thePage = thePage + "Object count : " + Runtime.ObjectCount.ToString + "<br>"
thePage = thePage + "Memory usage : " + Runtime.MemoryUsed.ToString + "<br>"
thePage = thePage + "<br>"
thePage = thePage + "Object count variation : " + format(Runtime.ObjectCount - initialObjectCount,"-0") + "<br>"
thePage = thePage + "Memory usage variation : " + format(Runtime.MemoryUsed - initialMemoryUsed,"-0") + "<br>"
thePage = thePage + "</body></html>"
response.Status = 200
response.Write thePage
return true
Here are my statistics, running in debug mode on MacBook Pro M2 MacOS 14.1.2:
after 1 request:
Object count : 6803
Memory usage : 9443216
Num requests : 500
Object count : 14183
Memory usage : 22877824
Num requests : 1000
Object count : 21682
Memory usage : 22817472
In comparison, 2023r2.1 also had leaks, but a lot less:
Num requests : 1
Object count : 6568
Memory usage : 9153968
Num requests : 500
Object count : 7442
Memory usage : 14587216
Num requests : 1000
Object count : 8442
Memory usage : 15803920
For comparison, I made a small desktop project using ServerSocket and this code in the tcpsocket connected event:
'use static to have the entire code in one page without any dependencies to properties
static NumRequests as integer
static initialObjectCount as integer
Static initialMemoryUsed as integer
'initialize
if initialObjectCount = 0 then initialObjectCount = Runtime.ObjectCount
if initialMemoryUsed = 0 then initialMemoryUsed = Runtime.MemoryUsed
'increment number of requests
NumRequests = NumRequests + 1
'build the page
var pagelines() as string
pagelines.add "<html><head><title>test</title></head><body>"
pagelines.add "Num requests : " + NumRequests.ToString
pagelines.add "Object count : " + Runtime.ObjectCount.ToString
pagelines.add "Memory usage : " + Runtime.MemoryUsed.ToString
pagelines.add "<br>"
pagelines.add "Object count variation : " + format(Runtime.ObjectCount - initialObjectCount,"-0")
pagelines.add "Memory usage variation : " + format(Runtime.MemoryUsed - initialMemoryUsed,"-0")
pagelines.add "</body></html>"
var page as string = join(pagelines,"<br>")
'build the header
var headerlines() as string
headerlines.Add "HTTP/1.1 200 OK"
headerlines.Add "Content-Type: text/html"
headerlines.Add "Date: Sun, 07 Jan 2024 19:36:53 GMT"
headerlines.Add "X-Content-Type-Options: nosniff"
headerlines.Add "X-Frame-Options: SAMEORIGIN"
headerlines.Add "Content-Length: " + page.Length.ToString
var header as string = join(headerlines,&u0D+&u0A)
var fullpage as string = header + &u0D+&u0A + &u0D+&u0A + page
'write all
me.Write fullpage
me.Flush
And here are the stats for this:
Num requests : 1
Object count : 98
Memory usage : 8199920
Num requests : 500
Object count : 54
Memory usage : 11687712
Num requests : 1000
Object count : 54
Memory usage : 11676992
Let me know if you have any insight.