Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Memory leak in php-opencv? #13

@Jeppelelle

Description

@Jeppelelle

Sorry for making yet another thread but i found what seems to be a memory issue.

I was working yesterday & today and noticed that my server became very slow after a couple of minutes & it turned out that everytime i used php-opencv on my website the memory usage increased by 200mb per image that was processed, the memory did not get released & after about 30 images all my memory was allocated & the server started using swap memory, so it became really slow:

https://i.imgur.com/YgyeXDl.png (php-fpm uses almost 8GiB of memory in total)

OpenCV has some memory leak issues when using Mat functions/objects & without using delete[] and/or release() properly & since php-opencv uses Mat for blobFromImage etc i checked the sourcecode, primarily "opencv_mat.cc" but it seems like the function "opencv_mat_free_obj()" should release/delete the memory properly of obj->mat & in "opencv_dnn.cc" i added "delete new_obj->mat;" for blobFromImage (just to try to debug the memory leak), i re-compiled & installed the .so again & restarted my server but i still had memory leaks.

I tested installing php-opencv on 3 different Debian10 servers & all of them had the same issue, i asked a friend that uses Ubuntu 18.04.03 if he had the same issue & he said they have, they "solved" it by changing the pool settings to:

pm = ondemand
pm.process_idle_timout = 10s
pm.max_requests 20

These settings incredible low for a production server so the performance suffers alot

So, have anyone else noticed a memory leak on your computer/server when using php-opencv?

I will read through the sourcecode again & see if there is any memory related problems i can find but when i checked earlier today i could not see any obvious issues so maybe there is an issue with ZEND instead? Or the interface between php-opencv and ZEND?

All my servers have default settings & everything is installed from the official repositories (apt install) & all .ini files are unchanged from default

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