surface_free

Destroys the surface, freeing it from memory.

Syntax:

GML Code Example

surface_free(surface_id);


Argument Description
surface_id The ID of the surface to be freed.


Returns: N/A


Description

When you are working with surfaces, you should always use this function whenever you are finished using them. Surfaces take up space in memory and so need to be removed, normally at the end of a room, but it can be done at any time depending on the use you put them to. Failure to do so can cause memory leaks which will eventually slow down and crash your game.

NOTE: When working with surfaces there is the possibility that they can cease to exist at any time due to them being stored in texture memory. You should ALWAYS check that a surface exists using surface_exists before referencing them directly. For further information see Surfaces.


Example:

GML Code Example

if keyboard_check_pressed(vk_escape)
    {
    surface_free(surf);
    room_goto(rm_Menu);
    }
 

The above code checks for a key press and if it detects one it frees the memory reserved for the surface indexed in the variable "surf" and then changes room.


Back: Surfaces



No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here