TL;DR: Is an IOSurfaceRef
a valid surface to write to after it has been purged and its state changed to kIOSurfacePurgeableEmpty
?
I'm trying to get a better understanding of what it means for an IOSurface
to be purged. The only documentation I have come across is in IOSurfaceRef.h
and the only sample code I've come across is in WebKit.
I'm using the command line tool memory_pressure
to simulate a critical memory pressure environment for 10 seconds like so:
> memory_pressure -S -s 10 -l critical
I've written a very simple application that allocates 100 IOSurfaces
with identical properties. When I use Instruments to measure the memory allocations, I see VM: IOSurface
at roughly 6GB, which is about 6MB for each surface. (4096x4096x4)
I then change the purgeable state of each IOSurface
to kIOSurfacePurgeableVolatile
and run the memory_pressure simulation.
Instruments still reports that I have 6GB of surfaces allocated. However, if I check the purgeable state of each surface, they are marked as kIOSurfacePurgeableEmpty
.
So it looks like they were successfully purged, but the memory is still allocated to my application. Why is that and what condition are these surfaces in?
The header file states that I should assume they have "undefined content" in them. Fair enough.
But is the actual IOSurfaceRef
or IOSurface *
object still valid? I can successfully query all of its properties and I can successfully lock it for reading and writing.
Am I allowed to just reuse that object even though its contents were purged or do I have to discard that instance and create an entirely new IOSurface?
macos 10.14