Discussion:
[Swig-devel] C# gc tests failure fix
Vadim Zeitlin
2015-07-05 00:07:22 UTC
Permalink
On Sat, 04 Jul 2015 13:54:46 -0700 GitHub <***@github.com> wrote:

G> Commit: c767b33c3f0bc7e30ac00214e77f0fc572678e6b
G> https://github.com/swig/swig/commit/c767b33c3f0bc7e30ac00214e77f0fc572678e6b
G> Author: William S Fulton <***@fultondesigns.co.uk>
G> Date: 2015-07-03 (Fri, 03 Jul 2015)
G>
G> Changed paths:
G> M Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs
G> M Examples/test-suite/csharp/li_std_auto_ptr_runme.cs
G>
G> Log Message:
G> -----------
G> C# gc tests failure fix
G>
G> Sometimes the GC just won't run the finalizers, so we output a warning
G> instead of throwing an error, so now the test-suite will pass but with a
G> warning if the number of objects is not as expected.

FWIW I had the same problem in our own unit tests for C# wrappers and
could solve it, apparently reliably, using

GC.Collect();
GC.WaitForPendingFinalizers();

Couldn't we do the same here?

G> li_std_auto_ptr was failing during Appveyor testing
G>
G> An equivalent change was put into the corresponding Java runtime tests a
G> while back.

And for Java just calling System.gc() seems to do the trick.

Regards,
VZ
William S Fulton
2015-07-05 11:20:57 UTC
Permalink
Post by Vadim Zeitlin
G> Commit: c767b33c3f0bc7e30ac00214e77f0fc572678e6b
G> https://github.com/swig/swig/commit/c767b33c3f0bc7e30ac00214e77f0fc572678e6b
G> Date: 2015-07-03 (Fri, 03 Jul 2015)
G>
G> M Examples/test-suite/csharp/li_boost_shared_ptr_runme.cs
G> M Examples/test-suite/csharp/li_std_auto_ptr_runme.cs
G>
G> -----------
G> C# gc tests failure fix
G>
G> Sometimes the GC just won't run the finalizers, so we output a warning
G> instead of throwing an error, so now the test-suite will pass but with a
G> warning if the number of objects is not as expected.
FWIW I had the same problem in our own unit tests for C# wrappers and
could solve it, apparently reliably, using
GC.Collect();
GC.WaitForPendingFinalizers();
Couldn't we do the same here?
These two testcase actually already do this. I've found that calling
Sleep for a few milliseconds is also important to get the gc to run,
most notably on single CPU systems as the finalizers run in a separate
low priority thread and without the Sleep, the thread won't run.
Nevertheless, with all this the gc still won't run, but there just
isn't any that it will be run unfortunately.
Post by Vadim Zeitlin
G> li_std_auto_ptr was failing during Appveyor testing
G>
G> An equivalent change was put into the corresponding Java runtime tests a
G> while back.
And for Java just calling System.gc() seems to do the trick.
Unfortunately I have not found this to be the case. Also,
System.runFinalization() and sleep need to be called for a greater
chance for the gc to run, but again there is no guarantee it will run
and sometimes it just doesn't.

William

Continue reading on narkive:
Loading...