fix(ocr): clear ncnn inference allocator caches - #5
Conversation
Clear ncnn blob and workspace pools after OCR completes. OCR 完成后清理 ncnn blob 和 workspace 缓存。 Log: 清理OCR推理缓存,避免重复识别内存持续增长 Influence: 保留模型权重,释放推理临时缓存;不改变公共接口。
Reviewer's GuideThis PR wires custom ncnn pool allocators into the OCR detection and recognition networks and clears their blob/workspace pools after each analyze() call to prevent inference cache memory from growing, without changing public interfaces or model weights. Sequence diagram for analyze and allocator clearingsequenceDiagram
participant App as PaddleOCRApp
participant DetNet as detNet
participant RecNet as recNet
App->>App: initNet()
App->>DetNet: detect(...)
App->>RecNet: rec(...)
alt [no textBoxes or needBreak]
App->>App: clearInferenceAllocators()
App-->>App: return false
else [textBoxes not empty]
App->>App: clearInferenceAllocators()
App-->>App: return true
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review★ 总体评分:100分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 当前代码已完美修复内存泄漏问题,无需额外修改。
// 保持现有实现即可:
void PaddleOCRApp::clearInferenceAllocators()
{
detBlobAllocator.clear();
detWorkspaceAllocator.clear();
recBlobAllocator.clear();
recWorkspaceAllocator.clear();
} |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider making
clearInferenceAllocators()exception/early-return safe by tying it to an RAII helper or a small scoped object inanalyze()so that future changes adding new return paths don’t accidentally bypass allocator cleanup. - If
PaddleOCRApp::analyze()can be called from multiple threads concurrently, clearing sharedPoolAllocatorinstances inclearInferenceAllocators()may introduce race conditions; clarifying the threading model or guarding allocator access would make this safer.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider making `clearInferenceAllocators()` exception/early-return safe by tying it to an RAII helper or a small scoped object in `analyze()` so that future changes adding new return paths don’t accidentally bypass allocator cleanup.
- If `PaddleOCRApp::analyze()` can be called from multiple threads concurrently, clearing shared `PoolAllocator` instances in `clearInferenceAllocators()` may introduce race conditions; clarifying the threading model or guarding allocator access would make this safer.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pengfeixx, wyu71 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Clear ncnn blob and workspace pools after OCR completes. OCR 完成后清理 ncnn blob 和 workspace 缓存。
Log: 清理OCR推理缓存,避免重复识别内存持续增长
Influence: 保留模型权重,释放推理临时缓存;不改变公共接口。
Summary by Sourcery
Manage and clear ncnn OCR inference memory pools after each analysis to prevent temporary allocator caches from growing unbounded while keeping model weights loaded.
Bug Fixes:
Enhancements: