문제

If I define an exception class

class Exception : public std::runtime_error
{
/*...*/
private:
    std::exception_ptr next;
    std::exception_ptr prev;
}

in which I refer to pending exceptions by next and new thrown exceptions while this is pending by prev, do the exception get freed after the exception is handled? The reason I'm asking is, that I once heard that std::exception_ptr is implemented in terms of reference counting which can lead to memory leaks, if there are reference cicles as I produced in this class.

도움이 되었습니까?

해결책

The reason I'm asking is, that I once heard that std::exception_ptr is implemented in terms of reference counting [...]

Not necessarily, but it could be. Paragraph 18.8.5/6 of the C++11 Standard mentions this in a note:

typedef unspecified exception_ptr;

[...]

6 [ Note: An implementation might use a reference-counted smart pointer as exception_ptr. —end note ]

Therefore, you may not want to establish cycles of exception_ptr.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top