[Gambas-bugtracker] Bug #2793: HTTPClient Memory Leak

bugtracker at gambaswiki.org bugtracker at gambaswiki.org
Sat Sep 30 23:37:52 CEST 2023


http://gambaswiki.org/bugtracker/edit?object=BUG.2793&from=L21haW4-

Comment #2 by Benoît MINISINI:

OK, I think I get it.

Before the recent changes, the internal CURL handle was recreated and destroy at each request.

Now it is kept and reused until the HttpClient is freed.

But you wrote code that never frees its HttpClient objects: each time you make a request, you create a new DegApp object. This object creates a new HttpClient, stored in the DegApp object, and using the same object as event observer. So there is a reference loop that prevents the DegApp object and the HttpClient to be freed.

So before the recent changes, there was no internal CURL handle leak, only a memory leak of two objects referencing each other that hence cannot be freed.

You can break the reference loop by assigning NULL to the global variable holding the HttpClient object, once you are done with it.

If you can create only one DegApp object, you can reuse the same HttpClient object again and again. But then you must create an "Exit" method that assigns NULL to the variable holding the HttpClient object, and call that method when you are done with your DegApp object.




More information about the Bugtracker mailing list