Skip to content

core(TLS): implement releasing of ThreadData with thread termination#15692

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
alalek:core_tls_handle_thread_termination
Oct 29, 2019
Merged

core(TLS): implement releasing of ThreadData with thread termination#15692
opencv-pushbot merged 1 commit intoopencv:3.4from
alalek:core_tls_handle_thread_termination

Conversation

@alalek
Copy link
Copy Markdown
Member

@alalek alalek commented Oct 13, 2019

Merge with contrib: opencv/opencv_contrib#2316

resolves #9745

  • move TLS & instrumentation code out of core/utility.hpp
  • TLSData lost .gather() method (to dispose thread data on thread termination)
  • use TLSDataAggregator for reliable collecting of thread data
  • prefer using of .detachData() instead of .gather() method

TODO:

  • propose API for reliable gathering of thread data
  • fix trace.cpp
  • additional tests
  • ? backward compatibility mode

- move TLS & instrumentation code out of core/utility.hpp
- (*) TLSData lost .gather() method (to dispose thread data on thread termination)
- use TLSDataAccumulator for reliable collecting of thread data
- prefer using of .detachData() + .cleanupDetachedData() instead of .gather() method

(*) API is broken: replace TLSData => TLSDataAccumulator if gather required
(objects disposal on threads termination is not available in accumulator mode)
@codars
Copy link
Copy Markdown

codars commented Oct 26, 2019

Hi @alalek, I'm having OpenCV memory leak issues reported by heaptrack on Linux, I saw your pr is merging into version 3.4, I'm wondering if 4.x also has the same problem? Will you merge this into 4.x as well?

@codars
Copy link
Copy Markdown

codars commented Oct 29, 2019

@alalek any plan to merge this into 4.x?

@mshabunin
Copy link
Copy Markdown
Contributor

@CodArs-van , it have been merged to master.

@remember505
Copy link
Copy Markdown

Hi @alalek .First of all, I am very grateful for the repair of the opencv async memory leak. This has also been verified after the update of the opencv version(such as 4.2), but now another problem encountered is somewhat similar. The same version(opencv 4.2) is also frequently used async (or std::thread)to open threads, in the child thread Calling opencv interfaces such as canny(or remap), there is a problem of continuous memory growth, do you know why?
This is my test code.

for (size_t i = 0; i < 1000000; i++) {
        std::async(std::launch::async, []() {
            cv::Mat binary_image_;
            std::cout << cv::utils::getThreadID() << std::endl;
            cv::Mat mImageGray = cv::imread("1.png", 1);
            cv::Canny(mImageGray, binary_image_, 12, 60);
        }).wait();
    }

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants