Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit edaa8d6

Browse filesBrowse files
committed
Unit test for np.array memory disposal
1 parent 2f1fb09 commit edaa8d6
Copy full SHA for edaa8d6

File tree

Expand file treeCollapse file tree

1 file changed

+32
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+32
-0
lines changed

‎test/Numpy.UnitTest/NumPy_array_creation.tests.cs

Copy file name to clipboardExpand all lines: test/Numpy.UnitTest/NumPy_array_creation.tests.cs
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,38 @@ public void full_likeTest()
355355
#endif
356356
}
357357

358+
[TestMethod]
359+
public void arrayLeakTest()
360+
{
361+
var arr = new double[10_000_000];
362+
using (var process = System.Diagnostics.Process.GetCurrentProcess())
363+
{
364+
long memStart;
365+
long getMemAfterGc()
366+
{
367+
GC.Collect(2, GCCollectionMode.Forced, true, true);
368+
process.Refresh();
369+
return process.PrivateMemorySize64;
370+
}
371+
long getOutstandingMem() => getMemAfterGc() - memStart;
372+
373+
var ones = np.ones(10_000_000); // python runtime warmup
374+
ones.Dispose();
375+
376+
memStart = getMemAfterGc();
377+
378+
ones = np.ones(10_000_000);
379+
Assert.IsTrue(getOutstandingMem() > 70_000_000);
380+
ones.Dispose();
381+
Assert.IsTrue(getOutstandingMem() < 1_000_000);
382+
383+
var array = np.array(arr);
384+
Assert.IsTrue(getOutstandingMem() > 70_000_000);
385+
array.Dispose();
386+
Assert.IsTrue(getOutstandingMem() < 1_000_000);
387+
}
388+
}
389+
358390
[TestMethod]
359391
public void arrayTest()
360392
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.