Project

General

Profile

The lacking use of smart pointers confuses me

Added by Alexander Theißen about 10 years ago

It is not clear to me when I am responsible for an object I allocated and when not.

The manual makes it clear that the application is responsible for destroying all widgets in it's view hierarchy.

But what about other pointers? I learned (from a crash) that the application destroys it's localized strings on destruction. But what about WCombinedLocalizedStrings. Does it destroy all it's WMessageResourceBundle on destruction?

What about other things? For example the WValidator on a WFormModel? Does it get destroyed when the form model destructs? Does the WTemplateFormView destroy it's model?

Without testing I have no clue. Is there some clear rule when I am responsible for destroying an object?


Replies (1)

RE: The lacking use of smart pointers confuses me - Added by Koen Deforche about 10 years ago

Hey,

The documentation will in general state what happens with ownership (if it doesn't, that's a bug).

As to your specific questions:

http://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WCombinedLocalizedStrings.html#a0a51b8245adf805bf32533c32fa994f0

Ownership of the resolver is transferred.

http://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WFormModel.html#a953379029989eb628f873e76480d2e61

If the validator has no ownership yet, the form model will take ownership.

WTemplateFormView does not take ownership of the model; in fact it's never assigned a model; it is not linked to a specific model.

Regards,

koen.

    (1-1/1)