Answer the question
In order to leave comments, you need to log in
Smart pointers, creation in a loop, or what to use instead?
Greetings!
In general, background:
In a separate thread in a cycle, I create a class, generate a signal (Qt emit ....), in the signal parameters, a pointer to this class,
several slots in several different threads are subscribed to this signal.
In order not to free resources later manually (after all the slots have worked), I decided to use smart pointers.
Currently QSharedPointer.
After the transition, an incredibly hard-to-find bug appeared, namely, memory wasting (if you go back, then everything is OK).
And it can work normally for a day, and then start eating up the RAM.
Once upon a time, either in the docks or on the forums, I heard a mention that smart pointers should not be used in cycles.
Purely theoretically, why and is this so?
If so, then how is it better to release resources if it is not known in advance how many slots will be subscribed to the signal and, moreover, which of the slots will subscribe last (what would be released in it)?
Answer the question
In order to leave comments, you need to log in
Once upon a time, either in the docks or on the forums, I heard a mention that smart pointers should not be used in cycles.
Purely theoretically, why and is this so?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question