The secure implementations would lock a small part of the memory to not get swapped out, various operating systems provide this functionality. In linux mlock systemcall and VirtualLock in windows. This will prevent a certain section of memory from being swapped out and written to disk. Obviously you are usually limited in how much memory you may lock.
Allocate the random key in this part of memory and ensure other key related stuff, partial keys used during claculations etc. are all in the locked region.
When you are done write out zeros, to any part of memory which had the key or might have something related, like a round sub key.
If you leave the key or a round sub key around, someone may be able to read it, from memory or from disk after it gets written to swap. Deleting data fully from disk is much harder, especially with modern hard drives.
Nothing is fool proof, including using the methods I mentioned. If your attacker is sitting on the same machine as you there are some attack vectors hard to defend against, but we can make it as difficult as possible.