From patchwork Wed Aug 25 10:29:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 13486 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 8CB2FC3241 for ; Wed, 25 Aug 2021 10:29:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 5837568915; Wed, 25 Aug 2021 12:29:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="I/M75Ilo"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8392960504 for ; Wed, 25 Aug 2021 12:29:42 +0200 (CEST) Received: from Monstersaurus.local (cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2F4956EE; Wed, 25 Aug 2021 12:29:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1629887382; bh=tfqZw3AByu5F5pLe+NPcrF7kuScVn8SeUIuTT9vH+sY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I/M75IlojjGcW81gYvsGgv1W1wIjknkuH9k73YyTqIRy3S2ngFPtQ+YyxaaAb8Atz gYKiWciA1MEPR46EtBSD2RQGKIhjrBIj2ER2uIocJaKzMiMyYHDULK+GI1Mzzihx7/ Kc1UHuqH/zl7Qg3P8hu7ZT9usCX379eKCMzJ3oE4= From: Kieran Bingham To: libcamera devel Date: Wed, 25 Aug 2021 11:29:35 +0100 Message-Id: <20210825102937.3740405-4-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210825102937.3740405-1-kieran.bingham@ideasonboard.com> References: <20210825102937.3740405-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/5] Documentation: application-developer: Recommend unique_ptr for CameraManager X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The CameraManager object should be deleted when it is no longer used to prevent it from leaking. When the application closes, the memory will be released, but it would show up in reports from memory validation tools such as valgrind if not handled correctly. Recommend best-practices in the guide and ensure it is automatically cleaned up when the CameraManager goes out of scope. Signed-off-by: Kieran Bingham Reviewed-by: Laurent Pinchart --- Documentation/guides/application-developer.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Documentation/guides/application-developer.rst b/Documentation/guides/application-developer.rst index 442d8e6a512e..e2ed79d5173e 100644 --- a/Documentation/guides/application-developer.rst +++ b/Documentation/guides/application-developer.rst @@ -61,11 +61,15 @@ variable for the camera to support the event call back later: std::shared_ptr camera; Create a Camera Manager instance at the beginning of the main function, and then -start it. An application should only create a single Camera Manager instance. +start it. An application must only create a single Camera Manager instance. + +The CameraManager can be stored in a unique_ptr to automate deleting the +instance when it is no longer used, but care must be taken to ensure all cameras +are released explicitly. .. code:: cpp - CameraManager *cm = new CameraManager(); + std::unique_ptr cm = std::make_unique(); cm->start(); During the application initialization, the Camera Manager is started to @@ -560,6 +564,9 @@ uses, so needs to do the following: return 0; +In this instance the CameraManager will automatically be deleted by the +unique_ptr implementation when it goes out of scope. + Build and run instructions --------------------------