From 83a9aa8ccb766b6b73b87a1b29455a9681cc6d97 Mon Sep 17 00:00:00 2001 From: Kieran Bingham Date: Mon, 23 Aug 2021 14:43:54 +0100 Subject: simple-cam: Use a unique_ptr for the CameraManager The CameraManager should be released when it is no longer used. A unique_ptr will handle this automatically, and convey the lifetime of the object. Update simple-cam to show that managing the lifetime of the CameraManager is recommended practice. Reviewed-by: Jacopo Mondi Reviewed-by: Paul Elder Reviewed-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- simple-cam.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/simple-cam.cpp b/simple-cam.cpp index 8f7012b..5c16db6 100644 --- a/simple-cam.cpp +++ b/simple-cam.cpp @@ -131,8 +131,15 @@ int main() * * The CameraManager provides a list of available Cameras that * applications can operate on. + * + * When the CameraManager is no longer to be used, it should be deleted. + * We use a unique_ptr here to manage the lifetime automatically during + * the scope of this function. + * + * There can only be a single CameraManager constructed within any + * process space. */ - CameraManager *cm = new CameraManager(); + std::unique_ptr cm = std::make_unique(); cm->start(); /* -- cgit v1.2.1