Skip to content

Memory issue in RF #5629

Open
Open

Description

@emilezwiggelaar

I have a question about memory usage of Robot Framework. I have some test cases that create many variables using VAR with a lot of text in them and I notice memory usage that I wouldn't expect. When the first testcase runs the memory usage increases and when the second testcase starts the memory usage increases again with the same amount where I would expect that the memory usage drops after the first test stops since the created variables don't exist anymore.

Hard to explain using words, so I've added an image of running 4 of sunch testcases in one run. You see that the memory just keeps increasing till the last testcase has run. (TC001A and TC004 through 7)

Image

Extra info... When I move the creation of the variables to a keyword, the memory does not increase at all {or hardly increases) during the whole run. (TC001 in the suite)

*** Settings ***
Documentation       Test memory usage in case many strings are used
Library             DateTime
Library             String
Test Tags           strings

*** Variables ***
${ITERATIONS}    200

*** Test Cases ***
TC001 Using A Keyword
    [Documentation]    The keyword cleans the variables up as expected
    ${random_str}    Generate Start String
    Log Timestamp
    FOR    ${i}    IN RANGE    ${ITERATIONS}
        Build String    ${random_str}    ${i}
    END
    Sleep    5 seconds
    Log To Console    ${\n}Number of iterations was ${i}

TC001A Using A Keyword And Capturing Return Value
    [Documentation]    Memoray stays allocated till the end of the testrun
    ${random_str}    Generate Start String
    Log Timestamp
    FOR    ${i}    IN RANGE    ${ITERATIONS}
        ${random_str${i}}    Build String    ${random_str}    ${i}
    END
    Sleep    5 seconds
    Log To Console    ${\n}Number of iterations was ${i}

TC002 Use Instant Clean-up
    [Documentation]    Instant clean up, no memory usage visible
    ${random_str}    Generate Start String
    Log Timestamp
    FOR    ${i}    IN RANGE    ${ITERATIONS}
        # Change content of variable in each iteration
        VAR    ${result}    ${i}    ${random_str}    separator=${SPACE}
        # Create a new variable in each iteration
        VAR    ${result${i}}    ${i}    ${random_str}    separator=${SPACE}
        ${padded}    Evaluate    f"{int(${i}):05d}"
        ${ts}    Get Time    format=%Y-%m-%d %H:%M:%S.%f
        Log To Console    ${padded}: ${ts}
        VAR    ${result${i}}    ${EMPTY}
    END
    Sleep    5 seconds
    Log To Console    ${\n}Number of iterations was ${i}

TC003 Use clean-up In For Loop
    [Documentation]    Clean up at the end, memory is released
    ${random_str}    Generate Start String
    Log Timestamp
    FOR    ${i}    IN RANGE    ${ITERATIONS}
        # Change content of variable in each iteration
        VAR    ${result}    ${i}    ${random_str}    separator=${SPACE}
        # Create a new variable in each iteration
        VAR    ${result${i}}    ${i}    ${random_str}    separator=${SPACE}
        ${padded}    Evaluate    f"{int(${i}):05d}"
        ${ts}    Get Time    format=%Y-%m-%d %H:%M:%S.%f
        Log To Console    ${padded}: ${ts}
    END
    Sleep    5 seconds
    FOR    ${i}    IN RANGE    ${ITERATIONS}
        VAR    ${result${i}}    ${EMPTY}
    END
    Log To Console    ${\n}Number of iterations was ${i}

TC004 No Clean-up Part 1
    [Documentation]    Memoray stays allocated till the end of the testrun
    [Tags]    memory
    ${random_str}    Generate Start String
    Log Timestamp
    FOR    ${i}    IN RANGE    ${ITERATIONS}
        # Change content of variable in each iteration
        VAR    ${tc4_result}    ${i}    ${random_str}    separator=${SPACE}
        # Create a new variable in each iteration
        VAR    ${tc4_result${i}}    ${i}    ${random_str}    separator=${SPACE}
        ${padded}    Evaluate    f"{int(${i}):05d}"
        ${ts}    Get Time    format=%Y-%m-%d %H:%M:%S.%f
        Log To Console    ${padded}: ${ts}
    END
    Sleep    5 seconds
    Log To Console    ${\n}Number of iterations was ${i}

TC005 No Clean-up Part 2
    [Documentation]    Memoray stays allocated till the end of the testrun
    [Tags]    memory
    ${random_str}    Generate Start String
    Log Timestamp
    FOR    ${i}    IN RANGE    ${ITERATIONS}
        # Change content of variable in each iteration
        VAR    ${tc5_result}    ${i}    ${random_str}    separator=${SPACE}
        # Create a new variable in each iteration
        VAR    ${tc5_result${i}}    ${i}    ${random_str}    separator=${SPACE}
        ${padded}    Evaluate    f"{int(${i}):05d}"
        ${ts}    Get Time    format=%Y-%m-%d %H:%M:%S.%f
        Log To Console    ${padded}: ${ts}
    END
    Sleep    5 seconds
    Log To Console    ${\n}Number of iterations was ${i}

TC006 No Clean-up Part 3
    [Documentation]    Memoray stays allocated till the end of the testrun
    [Tags]    memory
    ${random_str}    Generate Start String
    Log Timestamp
    FOR    ${i}    IN RANGE    ${ITERATIONS}
        # Change content of variable in each iteration
        VAR    ${tc6_result}    ${i}    ${random_str}    separator=${SPACE}
        # Create a new variable in each iteration
        VAR    ${tc6_result${i}}    ${i}    ${random_str}    separator=${SPACE}
        ${padded}    Evaluate    f"{int(${i}):05d}"
        ${ts}    Get Time    format=%Y-%m-%d %H:%M:%S.%f
        Log To Console    ${padded}: ${ts}
    END
    Sleep    5 seconds
    Log To Console    ${\n}Number of iterations was ${i}

TC007
    [Documentation]    Memoray stays allocated till the end of the testrun
    [Tags]    memory
    ${random_str}    Generate Start String
    Log Timestamp
    FOR    ${i}    IN RANGE    ${ITERATIONS}
        # Change content of variable in each iteration
        VAR    ${tc6_result}    ${i}    ${random_str}    separator=${SPACE}
        # Create a new variable in each iteration
        VAR    ${tc6_result${i}}    ${i}    ${random_str}    separator=${SPACE}
        ${padded}    Evaluate    f"{int(${i}):05d}"
        ${ts}    Get Time    format=%Y-%m-%d %H:%M:%S.%f
        Log To Console    ${padded}: ${ts}
    END
    Sleep    5 seconds
    Log To Console    ${\n}Number of iterations was ${i}

*** Keywords ***
Build String
    [Documentation]    Contains de content of the for loop
    [Arguments]    ${random_str}    ${i}
    # Change content of variable in each iteration
    VAR    ${result}    ${i}    ${random_str}    separator=${SPACE}
    # Create a new variable in each iteration
    VAR    ${result${i}}    ${i}    ${random_str}    separator=${SPACE}
    ${padded}    Evaluate    f"{int(${i}):05d}"
    ${ts}    Get Time    format=%Y-%m-%d %H:%M:%S.%f
    Log To Console    ${padded}: ${ts}
    RETURN    ${result${i}}

Generate Start String
    [Documentation]    Create a start string for the testcases
    ${number_of_bytes}    Evaluate    1024 * 1024 * 25
    ${mb}    Evaluate    ${number_of_bytes} / (1024 * 1024)
    Log To Console    Start generating random string of ${mb} MB
    ${random_str}    Generate Random String    ${number_of_bytes}    [LETTERS][NUMBERS][PUNCTUATION]
    Log To Console    Finished generating random string of ${mb} MB
    RETURN    ${random_str}

Log Timestamp
    [Documentation]    Log Timestamp
    ${ts}    Get Time    format=%Y-%m-%d %H:%M:%S.%f
    Log To Console    ${ts}

Activity

  1. Lakitna commented on Apr 15, 2026

    @Lakitna

    When the memory becomes full, is memory cleared up?

    Underlying reason for asking: Python is a garbage-collected language. In basic terms, this means that every now and then a function runs that clears up unused memory. This memory includes variables, scopes, etc. Depending on the implementation (not 100% sure for Python), garbage collectors typically trigger on interval (e.g. every 5 minutes) and on "HALP, we're running out of system memory!".

    If the memory footprint is cleared up when you run out of system memory, this behavior may be due to the garbage collector.

  2. emilezwiggelaar commented on Apr 16, 2026

    @emilezwiggelaar
    Author
    Image

    The image I added now shows a run where I set the iterations in the script shown above a lot higher and then you see that it doesn't clear up the memory. I actually had a system freeze happening during TC006 after the memory of TC004 and TC005 was not cleared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions