A long time ago I wrote an SDL2 binding but stopped using it because of memory leaks causing the UI to crash and burn after about 20 minutes of continuous use. A real shame, I loved writing the UI in prolog!
Today I have come back to it... cutting to the chase, I first thought that I would rule out gprolog... I created an empty file called '
empty.pl' that is literally, empty, zero bytes.
-rw-r--r-- 1 seancharles staff 0 11 Mar 10:33 empty.pl
Then I started a new gprolog session, NOT the one produced by my build process with the SDL2 bindings, then, using "leaks" on El Capitan...
Process 2280: 2200 nodes malloced for 1029 KB
Failed to map remote region: [0x7fffffe6d000-0x7fffffe6e000] r-x shared memory (1 page) [root] (error: 1)
Process 2280: 0 leaks for 0 total leaked bytes.
So far so good, now I read in my empty Prolog source file,
| ?- [empty].
compiling /Users/seancharles/Downloads/gnuprolog-libsdl2/empty.pl for byte code... /Users/seancharles/Downloads/gnuprolog-libsdl2/empty.pl compiled, 0 lines read - 97 bytes written, 115 ms
Then re-run leaks:
leaks Report Version: 2.0
Process 2280: 2213 nodes malloced for 1029 KB
Failed to map remote region: [0x7fffffe6d000-0x7fffffe6e000] r-x shared memory (1 page) [root] (error: 1)
Process 2280: 1 leak for 64 total leaked bytes.
Leak: 0x7f9b21c033a0 size=64 zone: DefaultMallocZone_0x10c9cb000 length: 59 "/var/folders/5p/c_cpyzqd0v15vd5rnvnr7xlm0000gn/T/gplcmXtOKb"
I then re-imported the same file a few more times, and each time the number of leaks went up by one:
leaks Report Version: 2.0
Process 2280: 2220 nodes malloced for 1030 KB
Failed to map remote region: [0x7fffffe6d000-0x7fffffe6e000] r-x shared memory (1 page) [root] (error: 1)
Process 2280: 4 leaks for 256 total leaked bytes.
Leak: 0x7f9b21c033a0 size=64 zone: DefaultMallocZone_0x10c9cb000 length: 59 "/var/folders/5p/c_cpyzqd0v15vd5rnvnr7xlm0000gn/T/gplcmXtOKb"
Leak: 0x7f9b21c03420 size=64 zone: DefaultMallocZone_0x10c9cb000 length: 59 "/var/folders/5p/c_cpyzqd0v15vd5rnvnr7xlm0000gn/T/gplcUONsld"
Leak: 0x7f9b21c03510 size=64 zone: DefaultMallocZone_0x10c9cb000 length: 59 "/var/folders/5p/c_cpyzqd0v15vd5rnvnr7xlm0000gn/T/gplc2xrLwg"
Leak: 0x7f9b21e14cd0 size=64 zone: DefaultMallocZone_0x10c9cb000 length: 59 "/var/folders/5p/c_cpyzqd0v15vd5rnvnr7xlm0000gn/T/gplctG76Ve"
I don't yet know where this is happening or how I can track it down.. valgrind won't install on my version of OSX but it would be nice to pin it down and fix it up!
I am going to download and build this under Ubuntu, see if it does the same, and if so, try to find the leak using DDD and valgrind if I can... unless somebody beats me too it which I would love to be the case because then I can focus on my own code which leaks somewhere I am sure in the shady twilight world between C and Prolog.
Thanks,
Sean.