FreeImg

Syntax

FreeImg(Image)

Description

Releases a reference to a ProGUI image object previously created with CreateImg() or LoadImg(). Due to internal reference counting, the image memory and associated resources are only fully deallocated when the last reference to the image is released.

Parameters

Image
The handle of the ProGUI image object to release.

Return Value

This function does not return a value.

Remarks

It is crucial to call FreeImg() for every image handle obtained from creation or loading functions when it's no longer needed to prevent memory leaks. If an image handle is used by other objects (like brushes or borders), freeing your reference to the handle will not destroy the underlying image data until those other objects are also freed or release their reference. ProGUI automatically handles reference counting for images used in brushes, borders, and alternate sizes (ImgAddSize()).

Example

IncludeFile "ProGUI_PB.pbi"

StartProGUI()

MyImage = CreateImg(100, 100, RGB(0, 0, 255))

If MyImage
    Debug "Image created."
    ; Use the image...

    ; When done with the image handle:
    FreeImg(MyImage)
    Debug "Image reference released."
    MyImage = 0 ; Good practice to nullify the handle after freeing
Else
    Debug "Failed to create image."
EndIf

LoadedImage = LoadImg("my_icon.png") ; Assuming my_icon.png exists
If LoadedImage
    Debug "Image loaded."
    ; Use the loaded image...
    FreeImg(LoadedImage)
    Debug "Loaded image reference released."
EndIf

StopProGUI()

See Also

CreateImg, LoadImg, ImgGrab

Supported OS

Windows, Linux