OK, so if I have code like this:

SWModule *mod1 = mgr->getModule("KJV");
SWModule *mod2 = mgr->getModule("KJV");

Those two pointers are to an object owned by the SWMgr object and I should
simply let the variable go out of scope when I'm done with it? I should not
be calling any delete or free on the module itself, correct? If I have need
to manipulate the module separately, then I should instantiate a different
SWMgr object and fetch a pointer from it? I presume that's the reason you
have separate ones for search and retrieval?

--Greg

On Sat, Apr 5, 2025 at 10:51 AM Troy A. Griffitts <scr...@crosswire.org>
wrote:

> 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@crosswire.org
> > http://crosswire.org/mailman/listinfo/sword-devel
> > Instructions to unsubscribe/change your settings at above page
> _______________________________________________
> sword-devel mailing list: sword-devel@crosswire.org
> http://crosswire.org/mailman/listinfo/sword-devel
> Instructions to unsubscribe/change your settings at above page
>
_______________________________________________
sword-devel mailing list: sword-devel@crosswire.org
http://crosswire.org/mailman/listinfo/sword-devel
Instructions to unsubscribe/change your settings at above page

Reply via email to