Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$controller->getStateDetails() Memory Leak #126

Closed
0stone0 opened this issue Mar 31, 2023 · 1 comment
Closed

$controller->getStateDetails() Memory Leak #126

0stone0 opened this issue Mar 31, 2023 · 1 comment

Comments

@0stone0
Copy link

0stone0 commented Mar 31, 2023

Hi!

Thanks to your previous suggestion (#123) to use updateGroup to keep a state without any caching interfering, I was able to continue with my project.

Unfortunately I'm experiencing some memory issues when calling $controller->getStateDetails().


Consider the following test code:

public function run() {
    while (TRUE) {
        $this->updateState();

        // Log each song title to check caching
        foreach ($this->state as $group) {
            echo $group->media->title . PHP_EOL;
        }

        usleep(1000);
    }
}

public function updateState() {
    $state = [];

    foreach ($this->sonos->getControllers() as $controller) {

        $controller->updateGroup();

        $group = new \StdClass();
        $group->group = $controller->getGroup();
        $group->state = $controller->getStateName();
        $group->room  = $controller->getRoom();

        echo 'MEM_DETAILS_BEFORE: ' . memory_get_usage() . PHP_EOL;
        $details = $controller->getStateDetails();
        echo ' MEM_DETAILS_AFTER: ' . memory_get_usage() . PHP_EOL;

        $media = new \StdClass();
        $media->title = $details->getTitle();
        $media->albumArt = $details->getAlbumArt();

        $group->media = $media;

        $state[] = $group;
    }

    $this->state = $state;
}

Each Iteration, the used memory is increased, evententually resulting in an OutOfMemory expection.

MEM_DETAILS_BEFORE: 3497128
 MEM_DETAILS_AFTER: 3498048
MEM_DETAILS_BEFORE: 3499648
 MEM_DETAILS_AFTER: 3499880
MEM_DETAILS_BEFORE: 3501264
 MEM_DETAILS_AFTER: 3501288
....

I've searched the Controller and ControllerState classed but was unable to find anything that could cause this, or how to prevent it.


Would love any suggestions on how to keep this 'state machine' running without leaking memory.

Thanks again!

@duncan3dc
Copy link
Owner

Unfortunately this is an issue with the SoapClient that PHP ships with, it's been reported before in #86 so I'll close this issue and we can track it there.

I don't think there are any workarounds available, as it's happening internally in PHP. If I get some time I'll look into any options for using a different extension/library for soap interactions

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

No branches or pull requests

2 participants