First, I create a RAM disk, like so:

diskutil erasevolume APFS RAM_Disk_4096MB $(hdiutil attach -nomount ram://8388608)

At first it occupies no RAM (system memory), as it is empty. When I copy/move files to it, in Activity Monitor's Memory section process diskimages-helper Memory column (usage) becomes exactly what the size of a file I copied is (as verified by ncdu and Disk Utility's Used: section for that RAM disk volume).

The problem is that when I delete a file from my RAM disk, Memory used by diskimages-helper does not go away. The only way to free it up is to either eject the RAM disk volume or kill the diskimages-helper process (practically the same thing).

From my research, as I continue to copy/move/remove files to/from my RAM disk the diskimages-helper memory usage grows untill it hits the 4GB mark (the amount allocated to the RAM disk). Once again, deleting files from RAM disk does not free up any memory used by diskimages-helper.

The question is then, how can I get my RAM disk/diskimages-helper process to only use the memory needed? And subsequently release whatever memory used to be allocated to now deleted files? Command line answers are preffered.

Note: RAM disk file system ideally has to be APFS or another sparse file capable file system.

To be clear, I'm not looking for a way to limit diskimages-helper's memory usage, as I can do so by simply changing my RAM disk size. The intention is to get diskimages-helper to only use whatever amount of memory is actually occupied by the files currently stored on the RAM disk (similar to how RAM disk/tmpfs works on Linux).

There was a similarly looking question with a key difference though, as this one is solved by simply ejecting the ram disk which frees up allocated memory. How do I get the memory allocated to a ramdisk back?

Potentially unimportant background: I use a streaming app called infuse, and it caches the entire movie/episode of whatever I watch/stream from my server. I do not want my already worn out SSD to carry the burden, so I'm using RAM disk for this app's cache directory. Please refrain from suggesting app-specific fixes, alternative apps, and such, the purpose of this question is to sort out RAM disk and diskimages-helper behaviour.

  • I don't think there's a way. Sparse bundles are supposed to be resizable, but I haven't found a way to create a sparsebundle as a RAM disk image. Even then, if you put the sparsebundle.image on a RAM disk and can resize it, you're back to the original problem of the mounted volume not being resized. I think you have to eject and recreate the volume to free up RAM.
    – Allan
    Commented Jan 6, 2023 at 4:02

1 Answer 1


I signed up to answer this question; it's the first time I've actually known the answer.

Each volume has its own bin (trash). When you delete something from the RAM disk, that's where it goes. If you empty the bin (trash) or open it and delete the file from there, that should give you your RAM back.

Sorry that's not your preferred Terminal solution. For that, I navigated to a folder deleted from RAM disk and found it inside a mysterious 501 directory, which was inside .Trashes (not .Trash). You'll need to sudo while there.

  • Unfortunately, this does not seem to be relevant to the issue I'm facing. I should've mentioned that I am deleting files/folder either with ⌘+⌥+␡ or with rm, i.e. skipping trash bin, so they don't even show up in the bin (.Trashes). Just to doublecheck I tried deleting file normally so that it'd end up inside .Trashes/501 as you mentioned but removing it from there later did not free up RAM either.
    – mikeskk
    Commented Feb 22, 2023 at 5:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .