I get no error with your script regardless of how often I press space, which indicates that it might be something different than insufficient memory. Maybe a certain render target size or format is not supported by your hardware.

For finding out, print GetAvailableTextureMem(). d3d_texfree works also, but is only updated once per frame. If it's really a video memory issue, GetAvailableTextureMem() should return a low value immediately before the error. If not, it's a system memory issue or something different.

Released memory is indeed not immediately flushed, but that should not be the problem since D3D has a memory manager.