From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Class (inherits from RuntimeException)

This exception is raised in certain cases when there is not enough available memory for the requested action.

ErrorNumber Message
Stack StackFrames


This exception is mostly useful with MemoryBlock and Picture when attempting to allocate large blocks of memory that would exceed the remaining available memory.

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.

Sample Code

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.

Sub Open
myPicture = New Picture(Logo.Width, Logo.Height)
myPicture.Graphics.DrawPicture(Logo, 0, 0)
Catch err As OutOfMemoryException
MessageBox("Insufficient memory to draw the picture!")
End Try

See Also

RuntimeException class; Function, Raise statements; Nil datatype; Exception, Try statements.