VSZ is just the reserved virtual memory space, RSS is the actual memory used, so around 33MB - still seems like a lot for a program that does almost nothing, but maybe it’s buffers for the renderer (possibly even in the GPU driver’s userspace part)?
I think having lots of allocs after some time is not surprising, IIRC SDLs internal event queue uses malloc() for each event - and most of those allocations seem to be freed again.
It’s weird though that there’s around 2000 allocs without corresponding free - does that change if you call SDL_Quit(); at the end?
BTW: You don’t have to allocate your event on the heap, you can as well do
I’m not sure where the remaining about 1000 allocs that aren’t freed come from, maybe the libGL or some other system lib allocates things that aren’t freed (because they’re only allocated once and are freed automatically when the process ends anyway).
Doing on heap I can allocate in some initialization function and return just a pointer instead using globals (that I’m just using here for sake of simplicity).
That doesn’t make sense.
If you need them globally, you can as well use a global SDL_Event instead of a global SDL_Event* (but even then, what use is having only the last polled event globally?)
If you only need them in the function that calls SDL_PollEvent() (which is usually the case), just make it a local variable in that function as I suggested, so it gets allocated on the stack, no need to allocate it on the heap.