Free

SRON provides runtime memory management using 'free' attribute. 'free' allows you to deallocate a variable's memory space.

NOTE: After the variable is freed, it cannot be accessed anymore. But the memory will still be available to other variables if they own the same memory block.

Syntax:

    free : variable_name

Example:

{
    name : MAIN

    Int val = 27

    println(val)

    free : val

    println(val)
}

OUTPUT:

27

In 'MAIN.srb':
VariableNotFoundException Caught :
||>> While retreving the value of a variable.

    > Reason 1: Specified Variable not found !
    > Reason 2: Specified variable is freed up before.       

    ||> Solution: Input a valid variable that already exists.

NOTE: Use it wisely because if you try to access a variable after it was freed, then your program will suddenly exit with code 1.

Last updated