Memory leak

Support
  • Hi, some of my customers are experiencing heavy memory leaks in just some hours:
    45075c8f-5aa5-4f98-bc2b-3c17a7584450-image.png
    88fff9eb-1172-499a-aa70-e27ec2add30e-image.png

    e8222d35-18f7-46f1-b425-98dec2045798-image.png

    I've seen on this forum that @support has fixed a memory leak for "reset" function few months ago, I'm also using the reset function and I guess this is where it is being leaked

    Would you please look into that and let me know ? Thank you

  • bump @Fox @support

  • Hey @Fox @support
    I am still experiencing the issue and found exactly how you can replicate it.

    Make a script looping through "Reset" function :
    -> Run the script on any computer, it will work normally
    -> Compile the script, and run it on any computer you will have insane data leak

    Seems like compiling the script for my customers to use is the reason why it happens.

  • @thotho
    Like this?
    7c7a9ef7-ced9-4a33-8672-228ef8e7243e-image.png

  • I don't know if this works but basically yes, I'm loading pages, reset after doing some action, and loop to get to begining of my script with new proxy and the data leak occurs

  • I know for sure it is the Reset function doing shit for compiled script, because my customers have the option to enable or disable it and there is no data leak when they disable it

  • @thotho
    Thank you.
    How quickly does a leak start? By the way, in the first post you attached a screenshot with a folder of temporary profiles. Is your RAM or storage memory leaking?

  • My customers also complaining from same issue @support and i dont use reset in my scripts

  • @gudolik said in Memory leak:

    My customers also complaining from same issue @support and i dont use reset in my scripts

    You can use the very old and well-known approach: just clean all directories in the profile directory with timestamps more than 30 minutes old, for example.
    Or, even better, with the latest access time feature.

    NOT tested:

    • Example 1
    
    # Note: This script deletes directories based on their last access time.
    
    # Define the path to the "prof" directory
    $directoryPath = "C:\path\to\prof"
    
    # Get the current time
    $currentTime = Get-Date
    
    # Find and delete directories older than 30 minutes based on last access time
    Get-ChildItem -Path $directoryPath -Directory | Where-Object {
        # Check if the directory was last accessed more than 30 minutes ago
        ($currentTime - $_.LastAccessTime).TotalMinutes -gt 30
    } | Remove-Item -Recurse -Force
    
    • Example 2

    More advanced script: It creates a lock file at the start to prevent multiple scripts from running simultaneously on the same directory.

    # Define the path to the "prof" directory
    $directoryPath = "C:\path\to\prof"
    
    # Define the lock file path
    $lockFilePath = "$directoryPath\.lock"
    
    function LockFileIsStale {
        $lockFile = Get-Item -Path $lockFilePath -ErrorAction SilentlyContinue
        if ($null -ne $lockFile) {
            $ageMinutes = (New-TimeSpan -Start $lockFile.LastWriteTime -End (Get-Date)).TotalMinutes
            return $ageMinutes -gt 30
        }
        return $true
    }
    
    try {
        # Check for an existing lock file and determine if it's stale
        if (Test-Path -Path $lockFilePath) {
            if (-not (LockFileIsStale)) {
                Write-Host "Another instance is running or lock is not stale. Exiting..."
                exit
            } else {
                Write-Host "Lock file is stale. Proceeding with cleanup..."
            }
        }
    
        # Create or update the lock file to indicate this script instance is running
        $null = New-Item -Path $lockFilePath -ItemType File -Force
        Write-Host "Lock file created/updated. Proceeding with cleanup..."
    
        # Get the current time
        $currentTime = Get-Date
    
        # Find and delete directories older than 30 minutes based on last access time
        Get-ChildItem -Path $directoryPath -Directory | Where-Object {
            # Check if the directory was last accessed more than 30 minutes ago
            ($currentTime - $_.LastAccessTime).TotalMinutes -gt 30
        } | ForEach-Object {
            Remove-Item -Path $_.FullName -Recurse -Force
            Write-Host "Deleted: $($_.FullName)"
        }
    } catch {
        Write-Host "An error occurred: $_"
    } finally {
        # Ensure the lock file is removed after the work is done
        if (Test-Path -Path $lockFilePath) {
            Remove-Item -Path $lockFilePath
            Write-Host "Lock file removed. Cleanup completed."
        }
    }
    
    
  • I found this module with this option (but did not use it, so I am not 100% sure how it work)


    http://community.bablosoft.com/post/162258