Skip to content

Commit 75c7bab

Browse files
committed
Snipping OCR 메모리 누수 문제 수정
1 parent f926ba4 commit 75c7bab

File tree

4 files changed

+53
-50
lines changed

4 files changed

+53
-50
lines changed

MORT/OcrApi/OneOcr/OneOcr.cs

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class OneOcr
2828
private long Context { get; set; }
2929

3030
private bool _initalized;
31+
private long _pipeline;
32+
private long _opt;
3133

3234
// 안전한 DLL 검색 경로 등록 관련 필드
3335
private IntPtr _dllDirectoryCookie = IntPtr.Zero;
@@ -84,6 +86,45 @@ public async ValueTask InitalizeAsync()
8486
}
8587
}
8688

89+
// Model key and path
90+
string key = "kj)TGtrK>f]b[Piow.gU+nC@s\"\"\"\"\"\"4";
91+
string modelPath = Path.Combine(OneOcrPath, OneOcrModel);
92+
modelPath = Path.GetFullPath(modelPath);
93+
94+
var ctx = Context;
95+
Console.WriteLine($"OneOcr DLL Path: {modelPath}");
96+
// Create OCR pipeline
97+
long res = NativeMethods.CreateOcrPipeline(modelPath, key, ctx, out long pipeline);
98+
if(res != 0)
99+
{
100+
var msg = $"CreateOcrPipeline failed. res={res}, modelPath={modelPath}, dllPath={OneOcrPath}";
101+
Console.Error.WriteLine(msg);
102+
Debug.WriteLine(msg);
103+
return;
104+
}
105+
106+
// Set process options
107+
res = NativeMethods.CreateOcrProcessOptions(out long opt);
108+
if(res != 0)
109+
{
110+
var msg = $"CreateOcrProcessOptions failed. res={res}";
111+
Console.Error.WriteLine(msg);
112+
Debug.WriteLine(msg);
113+
// try to cleanup pipeline if needed (if native provides)
114+
return ;
115+
}
116+
117+
res = NativeMethods.OcrProcessOptionsSetMaxRecognitionLineCount(opt, 1000);
118+
if(res != 0)
119+
{
120+
var msg = $"OcrProcessOptionsSetMaxRecognitionLineCount failed. res={res}";
121+
Console.Error.WriteLine(msg);
122+
Debug.WriteLine(msg);
123+
return;
124+
}
125+
126+
_pipeline = pipeline;
127+
_opt = opt;
87128
_initalized = true;
88129
}
89130

@@ -111,52 +152,14 @@ public async ValueTask InitalizeAsync()
111152

112153
return path;
113154
}
114-
private bool _test;
115-
private long _pipeline;
116-
private long _opt;
155+
156+
117157
private Line[] RunOcr(Img img)
118158
{
119159
try
120160
{
121-
// Model key and path
122-
string key = "kj)TGtrK>f]b[Piow.gU+nC@s\"\"\"\"\"\"4";
123-
string modelPath = Path.Combine(OneOcrPath, OneOcrModel);
124-
modelPath = Path.GetFullPath(modelPath);
125-
126-
var ctx = Context;
127-
Console.WriteLine($"OneOcr DLL Path: {modelPath}");
128-
// Create OCR pipeline
129-
long res = NativeMethods.CreateOcrPipeline(modelPath, key, ctx, out long pipeline);
130-
if(res != 0)
131-
{
132-
var msg = $"CreateOcrPipeline failed. res={res}, modelPath={modelPath}, dllPath={OneOcrPath}";
133-
Console.Error.WriteLine(msg);
134-
Debug.WriteLine(msg);
135-
return null;
136-
}
137-
138-
// Set process options
139-
res = NativeMethods.CreateOcrProcessOptions(out long opt);
140-
if(res != 0)
141-
{
142-
var msg = $"CreateOcrProcessOptions failed. res={res}";
143-
Console.Error.WriteLine(msg);
144-
Debug.WriteLine(msg);
145-
// try to cleanup pipeline if needed (if native provides)
146-
return null;
147-
}
148-
149-
res = NativeMethods.OcrProcessOptionsSetMaxRecognitionLineCount(opt, 1000);
150-
if(res != 0)
151-
{
152-
var msg = $"OcrProcessOptionsSetMaxRecognitionLineCount failed. res={res}";
153-
Console.Error.WriteLine(msg);
154-
Debug.WriteLine(msg);
155-
return null;
156-
}
157-
158161
// Run OCR pipeline
159-
res = NativeMethods.RunOcrPipeline(pipeline, ref img, opt, out long instance);
162+
long res = NativeMethods.RunOcrPipeline(_pipeline, ref img, _opt, out long instance);
160163
if(res != 0)
161164
{
162165
var msg = $"RunOcrPipeline failed. res={res}";

MORT/Properties/Settings.Designer.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MORT/Properties/Settings.settings

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
<Profiles />
44
<Settings>
55
<Setting Name="MORT_VERSION" Type="System.String" Scope="Application">
6-
<Value Profile="(Default)">1.300V</Value>
6+
<Value Profile="(Default)">1.301V</Value>
77
</Setting>
88
<Setting Name="LAYER_TEXT" Type="System.String" Scope="Application">
99
<Value Profile="(Default)">MORT {0}
1010
레이어 번역창</Value>
1111
</Setting>
1212
<Setting Name="MORT_VERSION_VALUE" Type="System.Int32" Scope="Application">
13-
<Value Profile="(Default)">1300</Value>
13+
<Value Profile="(Default)">1301</Value>
1414
</Setting>
1515
<Setting Name="TOOLTIP_LIST" Type="System.String" Scope="Application">
1616
<Value Profile="(Default)">MORT를 처음 쓰시면 그 외-&gt; MORT 사용법을 확인해 주세요,
@@ -45,7 +45,7 @@ OCR 영역을 빠르게 추가하고 싶을 땐 빠른 OCR 영역을 사용하
4545
구글 OCR의 사용량은 실제 사용량과 다를 수 있습니다. 수시로 구글 콘솔에서 확인하셔야 합니다</Value>
4646
</Setting>
4747
<Setting Name="MORT_RELEASE" Type="System.String" Scope="Application">
48-
<Value Profile="(Default)">2025 11 30</Value>
48+
<Value Profile="(Default)">2025 12 01</Value>
4949
</Setting>
5050
<Setting Name="BASIC_TEXT" Type="System.String" Scope="Application">
5151
<Value Profile="(Default)">

MORT/app.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@
7373
<applicationSettings>
7474
<MORT.Properties.Settings>
7575
<setting name="MORT_VERSION" serializeAs="String">
76-
<value>1.300V</value>
76+
<value>1.301V</value>
7777
</setting>
7878
<setting name="LAYER_TEXT" serializeAs="String">
7979
<value>MORT {0}
8080
레이어 번역창</value>
8181
</setting>
8282
<setting name="MORT_VERSION_VALUE" serializeAs="String">
83-
<value>1300</value>
83+
<value>1301</value>
8484
</setting>
8585
<setting name="TOOLTIP_LIST" serializeAs="String">
8686
<value>MORT를 처음 쓰시면 그 외-&gt; MORT 사용법을 확인해 주세요,
@@ -115,7 +115,7 @@ OCR 영역을 빠르게 추가하고 싶을 땐 빠른 OCR 영역을 사용하
115115
구글 OCR의 사용량은 실제 사용량과 다를 수 있습니다. 수시로 구글 콘솔에서 확인하셔야 합니다</value>
116116
</setting>
117117
<setting name="MORT_RELEASE" serializeAs="String">
118-
<value>2025 11 30</value>
118+
<value>2025 12 01</value>
119119
</setting>
120120
<setting name="BASIC_TEXT" serializeAs="String">
121121
<value>

0 commit comments

Comments
 (0)