From Xojo Documentation
This exception is raised in certain cases when there is not enough available memory for the requested action.
Low-level memory situations are inherently problematic, especially if you are frequently requesting small blocks of memory (using MemoryBlock or Picture). Because of this, there is no guarantee that an OutOfMemoryException can even be raised. If the system memory has gotten critically low, the process itself may crash as it attempts to reserve memory in order to display an exception message.
In this situation, you might consider reserving a large block of memory up front and using that within your application rather than repeatedly requesting smaller blocks.
This example uses the Catch statement in a window's Open event handler to handle out of memory exceptions when trying to draw an imported gif image. The variable myPicture is a global property of type Picture. The picture "Logo" has been added to the Project Editor.
myPicture = New Picture(Logo.Width, Logo.Height)
myPicture.Graphics.DrawPicture(Logo, 0, 0)
Catch err As OutOfMemoryException
MsgBox("Insufficient memory to draw the picture!")