[Rprotobuf-yada] finalizer for messages
Romain Francois
romain.francois at dbmail.com
Wed Dec 16 17:26:38 CET 2009
I think the problem is now solved, and we have a cleaner package that
plays well (at least I think) with R's garbage collector.
> require( RProtoBuf )
Loading required package: RProtoBuf
Loading required package: Rcpp
> message <- new( tutorial.Person, id = 1 )
> message <- new( tutorial.Person, id = 1 )
> message <- new( tutorial.Person, id = 1 )
> message <- new( tutorial.Person, id = 1 )
> gc()
RProtoBuf finalizing Message (0x9258f68)
RProtoBuf finalizing Message (0x91ce378)
RProtoBuf finalizing Message (0x97f27b0)
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 260797 7.0 407500 10.9 350000 9.4
Vcells 210014 1.7 786432 6.0 500691 3.9
previously the 3 first messages did not free their memory after the
external pointer was GC'd.
I'll leave debugging messages as above for some time.
On 12/16/2009 12:49 PM, Romain François wrote:
>
> Now that I know how to work with external pointer finalizers (much
> easier than I anticipated; all covered in R-exts), I have added a
> finalizer for Message. We don't need to define them for **Descriptor
> because they don't belong to us, but we need to define them for messages
> to avoid memory leaks.
>
> So I have added them, now the package does not pass R CMD check. I think
> I need to be more careful when I access message fields of other
> messages, at the moment, I wrap up the pointer, where I think I should
> make a copy of the message.
>
> much more dbugging "fun" to come :( but should be manageaable:
>
> $ grep "Get.*Message" *.cpp
> extractors.cpp:
> new_RS4_Message_(&ref->GetRepeatedMessage( *message, fieldDesc, i ) ) ) ;
> extractors.cpp: res = PROTECT( new_RS4_Message_(
> &ref->GetMessage( *message, fieldDesc ) ) ) ;
> extractors.cpp: * Get the message descriptor of a Message
> identical.cpp:
> const GPB::Message* mm1 =&ref->GetRepeatedMessage( *m1, field_desc, j ) ;
> identical.cpp:
> const GPB::Message* mm2 =&ref->GetRepeatedMessage( *m2, field_desc, j ) ;
> identical.cpp: const
> GPB::Message* mm1 =&ref->GetMessage( *m1, field_desc ) ;
> identical.cpp: const
> GPB::Message* mm2 =&ref->GetMessage( *m2, field_desc ) ;
> read.cpp: throwException( "could not call
> factory->GetPrototype(desc)->New()", "MessageCreationException" ) ;
> read.cpp: throwException( "could not call
> factory->GetPrototype(desc)->New()", "MessageCreationException" ) ;
> read.cpp: throwException( "could not call
> factory->GetPrototype(desc)->New()", "MessageCreationException" ) ;
> rprotobuf.cpp: throwException( "could not call
> factory->GetPrototype(desc)->New()", "MessageCreationException" ) ;
> set.cpp:
> new_RS4_Message_(&ref->GetRepeatedMessage( *message, field_desc, i ) ) ) ;
>
> Romain
>
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/HlX9 : new package : bibtex
|- http://tr.im/Gq7i : ohloh
`- http://tr.im/FtUu : new package : highlight
More information about the Rprotobuf-yada
mailing list