From aa2ad3bbd2f4533e869a5a756d06cd017d2b0ac7 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 23 Jul 2013 23:18:22 +0200 Subject: Fix garbage collection of shared data. #1348 --- lib/Slic3r.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index a3761ac6b..aac355b36 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -86,7 +86,12 @@ sub parallelize { my $q = Thread::Queue->new; $q->enqueue(@items, (map undef, 1..$Config->threads)); - my $thread_cb = sub { $params{thread_cb}->($q) }; + my $thread_cb = sub { + my $result = $params{thread_cb}->($q); + Slic3r::thread_cleanup(); + return $result; + }; + @_ = (); foreach my $th (map threads->create($thread_cb), 1..$Config->threads) { $params{collect_cb}->($th->join); @@ -96,6 +101,18 @@ sub parallelize { } } +# call this at the very end of each thread (except the main one) +# so that it does not try to free existing objects. +# at that stage, existing objects are only those that we +# inherited at the thread creation (thus shared) and those +# that we are returning: destruction will be handled by the +# main thread in both cases. +sub thread_cleanup { + # prevent destruction of shared objects + no warnings 'redefine'; + *Slic3r::Object::XS::ZTable::DESTROY = sub {}; +} + sub encode_path { my ($filename) = @_; return encode('locale_fs', $filename); -- cgit v1.2.3