[sword-devel] Pointer Management
Troy A. Griffitts
scribe at crosswire.org
Sat Apr 5 11:51:42 EDT 2025
Hi Greg,
Typically in SWORD, the object/factory that created the object is
responsible for deleting the object unless a call was made to something
like 'clone' or 'create'. So, SWMgr will delete all the SWModule
objects it allowcates when the SWMgr object is deleted. If you have
multiple threads in your application, we recommend each thread have its
own SWMgr object because the same SWModule object instances are returned
each time a getModule() call is made to the same instance of SWMgr.
I usually have 3 SWMgr objects I interact with in my apps: one I create
for display, one I create for searching, and one I get from InstallMgr.
The exceptions, as mentioned above, are usually noted in the comments, e.g.,
https://github.com/bibletime/crosswire-sword-mirror/blob/trunk/include/swmodule.h#L486
https://github.com/bibletime/crosswire-sword-mirror/blob/trunk/include/swkey.h#L134
Hope this helps,
Troy
On 3/25/25 7:42 AM, Greg Hellings wrote:
> I have a question about pointer lifetime and management when
> interacting with libsword: who owns the lifetime and delete management
> of pointers coming out of the SWMgr and SWModule calls? For instance:
> if I create an SWMgr object and fetch a SWModule* from its get module
> methods, who owns deletion of that? Should I preserve the pointer and
> have SWMgr delete it when it gets deleted? Or does the caller need to
> own deletion of it? Is that instance of the SWModule shared with
> everyone else who calls the getter methods, or is it unique per
> invocation of the getter?
>
> A similar question regarding getting keys from a module instance. Does
> that key live with the module's cleanup, or does the caller now have
> responsibility for the instance?
>
> --Greg
>
> _______________________________________________
> sword-devel mailing list: sword-devel at crosswire.org
> http://crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page
More information about the sword-devel
mailing list