How can I free memory allocated when deserializing with boost::archive::text_iarchive

Thanks for your reply. Here is a code sample: std::istringstream istr; <* put data into istr here *> boost::archive::text_iarchive ia(istr_); Message* p_temp; ia & p_temp; mpBaseIncomingMessage = p_temp; // mpBaseIncomingMessage is of type (Message *) mpIncomingMessage = static_cast<SystemMessage*>(mpBaseIncomingMessage); // mpIncomingMessage is a pointer to a class derived from Message mObjectCallbackMap.process(mpIncomingMessage->mEvent); // execute a callback for this event delete mpIncomingMessage; // delete the allocated memory We then see a crash on either the " mObjectCallbackMap.process..." line or the " delete mpIncomingMessage", but only when certain actions are taken by the system. Any thoughts would be greatly appreciated. Regards, Adlai -----Original Message----- From: Boost-users [mailto:boost-users-bounces@lists.boost.org] On Behalf Of boost-users-request@lists.boost.org Sent: Monday, February 04, 2013 1:11 PM To: boost-users@lists.boost.org Subject: Boost-users Digest, Vol 3349, Issue 6 Send Boost-users mailing list submissions to boost-users@lists.boost.org To subscribe or unsubscribe via the World Wide Web, visit http://lists.boost.org/mailman/listinfo.cgi/boost-users or, via email, send a message with subject or body 'help' to boost-users-request@lists.boost.org You can reach the person managing the list at boost-users-owner@lists.boost.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Boost-users digest..." Today's Topics: 1. Re: Crediting the Work of Others (Bill Buklis) 2. How can I free memory allocated when deserializing with boost::archive::text_iarchive (Adlai Shawareb) 3. Re: in IOS, thread_info object is being destructed before the thread finishes executing (Nat Linden) 4. Re: Undirected version of dijkstra shortest path on directed graph. (Jeremiah Willcock) 5. Re: Crediting the Work of Others (Algocoders) 6. Re: How can I free memory allocated when deserializing with boost::archive::text_iarchive (Tim Moore) 7. [mpl::integral_c] Compiler Error with Visual Studio 2010 (Christian Henning) 8. Re: [mpl::integral_c] Compiler Error with Visual Studio 2010 (Nathan Crookston) ---------------------------------------------------------------------- Message: 1 Date: Mon, 04 Feb 2013 13:18:47 -0600 From: Bill Buklis <boostusr@pbjzone.com> To: boost-users@lists.boost.org Subject: Re: [Boost-users] Crediting the Work of Others Message-ID: <51100997.1050909@pbjzone.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed On 2/1/2013 1:33 PM, Algocoders wrote:
Only the last link for Chapter 11 actually works and there aren't any acknowledgements presented in that pdf. -- Bill ------------------------------ Message: 2 Date: Mon, 4 Feb 2013 19:46:54 +0000 From: Adlai Shawareb <adlai@vytronus.com> To: "boost-users@lists.boost.org" <boost-users@lists.boost.org> Subject: [Boost-users] How can I free memory allocated when deserializing with boost::archive::text_iarchive Message-ID: <842DD0CD91745A48B9355924E2CF0BEA114FEF3D@VYTRONUS-SBS.vytronus.local> Content-Type: text/plain; charset="us-ascii" Hi, Does anyone know how we can free memory that is dynamically allocated by boost::archive::text_iarchive when deserializing an archive? We have tried using 'delete' and free() on the pointer when we finish with it, but it results in a crash. How does Boost dynamically allocate memory, 'new', 'malloc', or other? We tried a shared_ptr, but were getting compile errors related to the include files, and have not gone back to track that down. So if there is a simple way to free the memory that would be best for our application. Thanks, Adlai Shawareb Vytronus, Inc.

A general comment on using this mailing list is to reply directly to the message, and to put the library in question in square brackets such as [serialization]. On 2/4/2013 9:29 PM, Adlai Shawareb wrote:
Serialization library is designed to work with symmetrically serialized/de-serialized data. How are you serializing the Message*? You can save yourself lots of time by using boost::polymorphic_downcast in situations like your usage of static_cast above to ensure you actually have a base pointer pointing to the derived type you think you have. Also creating a standalone minimal example demonstrating the problem usually helps you detect where things have gone awry. Jeff
participants (2)
-
Adlai Shawareb
-
Jeff Flinn