mirror of
https://github.com/godotengine/godot-docs.git
synced 2025-12-31 17:49:03 +03:00
93 lines
9.5 KiB
ReStructuredText
93 lines
9.5 KiB
ReStructuredText
:github_url: hide
|
|
|
|
.. DO NOT EDIT THIS FILE!!!
|
|
.. Generated automatically from Godot engine sources.
|
|
.. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
|
|
.. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/RefCounted.xml.
|
|
|
|
.. _class_RefCounted:
|
|
|
|
RefCounted
|
|
==========
|
|
|
|
**Inherits:** :ref:`Object<class_Object>`
|
|
|
|
**Inherited By:** :ref:`AESContext<class_AESContext>`, :ref:`AStar2D<class_AStar2D>`, :ref:`AStar3D<class_AStar3D>`, :ref:`AStarGrid2D<class_AStarGrid2D>`, :ref:`AnimationTrackEditPlugin<class_AnimationTrackEditPlugin>`, :ref:`AudioEffectInstance<class_AudioEffectInstance>`, :ref:`AudioStreamPlayback<class_AudioStreamPlayback>`, :ref:`CameraFeed<class_CameraFeed>`, :ref:`CharFXTransform<class_CharFXTransform>`, :ref:`ConfigFile<class_ConfigFile>`, :ref:`Crypto<class_Crypto>`, :ref:`DTLSServer<class_DTLSServer>`, :ref:`DirAccess<class_DirAccess>`, :ref:`ENetConnection<class_ENetConnection>`, :ref:`EditorExportPlatform<class_EditorExportPlatform>`, :ref:`EditorExportPlugin<class_EditorExportPlugin>`, :ref:`EditorFeatureProfile<class_EditorFeatureProfile>`, :ref:`EditorFileSystemImportFormatSupportQuery<class_EditorFileSystemImportFormatSupportQuery>`, :ref:`EditorInspectorPlugin<class_EditorInspectorPlugin>`, :ref:`EditorResourceConversionPlugin<class_EditorResourceConversionPlugin>`, :ref:`EditorResourcePreviewGenerator<class_EditorResourcePreviewGenerator>`, :ref:`EditorSceneFormatImporter<class_EditorSceneFormatImporter>`, :ref:`EditorScenePostImport<class_EditorScenePostImport>`, :ref:`EditorScenePostImportPlugin<class_EditorScenePostImportPlugin>`, :ref:`EditorScript<class_EditorScript>`, :ref:`EditorTranslationParserPlugin<class_EditorTranslationParserPlugin>`, :ref:`EditorUndoRedoManager<class_EditorUndoRedoManager>`, :ref:`EncodedObjectAsID<class_EncodedObjectAsID>`, :ref:`EngineProfiler<class_EngineProfiler>`, :ref:`Expression<class_Expression>`, :ref:`FileAccess<class_FileAccess>`, :ref:`HMACContext<class_HMACContext>`, :ref:`HTTPClient<class_HTTPClient>`, :ref:`HashingContext<class_HashingContext>`, :ref:`ImageFormatLoader<class_ImageFormatLoader>`, :ref:`JSON<class_JSON>`, :ref:`JavaClass<class_JavaClass>`, :ref:`JavaScriptObject<class_JavaScriptObject>`, :ref:`KinematicCollision2D<class_KinematicCollision2D>`, :ref:`KinematicCollision3D<class_KinematicCollision3D>`, :ref:`Lightmapper<class_Lightmapper>`, :ref:`MeshDataTool<class_MeshDataTool>`, :ref:`MultiplayerAPI<class_MultiplayerAPI>`, :ref:`Mutex<class_Mutex>`, :ref:`NavigationPathQueryParameters2D<class_NavigationPathQueryParameters2D>`, :ref:`NavigationPathQueryParameters3D<class_NavigationPathQueryParameters3D>`, :ref:`NavigationPathQueryResult2D<class_NavigationPathQueryResult2D>`, :ref:`NavigationPathQueryResult3D<class_NavigationPathQueryResult3D>`, :ref:`Node3DGizmo<class_Node3DGizmo>`, :ref:`OggPacketSequencePlayback<class_OggPacketSequencePlayback>`, :ref:`PCKPacker<class_PCKPacker>`, :ref:`PackedDataContainerRef<class_PackedDataContainerRef>`, :ref:`PacketPeer<class_PacketPeer>`, :ref:`PhysicsPointQueryParameters2D<class_PhysicsPointQueryParameters2D>`, :ref:`PhysicsPointQueryParameters3D<class_PhysicsPointQueryParameters3D>`, :ref:`PhysicsRayQueryParameters2D<class_PhysicsRayQueryParameters2D>`, :ref:`PhysicsRayQueryParameters3D<class_PhysicsRayQueryParameters3D>`, :ref:`PhysicsShapeQueryParameters2D<class_PhysicsShapeQueryParameters2D>`, :ref:`PhysicsShapeQueryParameters3D<class_PhysicsShapeQueryParameters3D>`, :ref:`PhysicsTestMotionParameters2D<class_PhysicsTestMotionParameters2D>`, :ref:`PhysicsTestMotionParameters3D<class_PhysicsTestMotionParameters3D>`, :ref:`PhysicsTestMotionResult2D<class_PhysicsTestMotionResult2D>`, :ref:`PhysicsTestMotionResult3D<class_PhysicsTestMotionResult3D>`, :ref:`RDAttachmentFormat<class_RDAttachmentFormat>`, :ref:`RDFramebufferPass<class_RDFramebufferPass>`, :ref:`RDPipelineColorBlendState<class_RDPipelineColorBlendState>`, :ref:`RDPipelineColorBlendStateAttachment<class_RDPipelineColorBlendStateAttachment>`, :ref:`RDPipelineDepthStencilState<class_RDPipelineDepthStencilState>`, :ref:`RDPipelineMultisampleState<class_RDPipelineMultisampleState>`, :ref:`RDPipelineRasterizationState<class_RDPipelineRasterizationState>`, :ref:`RDPipelineSpecializationConstant<class_RDPipelineSpecializationConstant>`, :ref:`RDSamplerState<class_RDSamplerState>`, :ref:`RDShaderSource<class_RDShaderSource>`, :ref:`RDTextureFormat<class_RDTextureFormat>`, :ref:`RDTextureView<class_RDTextureView>`, :ref:`RDUniform<class_RDUniform>`, :ref:`RDVertexAttribute<class_RDVertexAttribute>`, :ref:`RandomNumberGenerator<class_RandomNumberGenerator>`, :ref:`RegEx<class_RegEx>`, :ref:`RegExMatch<class_RegExMatch>`, :ref:`Resource<class_Resource>`, :ref:`ResourceFormatLoader<class_ResourceFormatLoader>`, :ref:`ResourceFormatSaver<class_ResourceFormatSaver>`, :ref:`ResourceImporter<class_ResourceImporter>`, :ref:`SceneState<class_SceneState>`, :ref:`SceneTreeTimer<class_SceneTreeTimer>`, :ref:`Semaphore<class_Semaphore>`, :ref:`SkinReference<class_SkinReference>`, :ref:`StreamPeer<class_StreamPeer>`, :ref:`SurfaceTool<class_SurfaceTool>`, :ref:`TCPServer<class_TCPServer>`, :ref:`TextLine<class_TextLine>`, :ref:`TextParagraph<class_TextParagraph>`, :ref:`TextServer<class_TextServer>`, :ref:`Thread<class_Thread>`, :ref:`TriangleMesh<class_TriangleMesh>`, :ref:`Tween<class_Tween>`, :ref:`Tweener<class_Tweener>`, :ref:`UDPServer<class_UDPServer>`, :ref:`UPNP<class_UPNP>`, :ref:`UPNPDevice<class_UPNPDevice>`, :ref:`WeakRef<class_WeakRef>`, :ref:`WebRTCPeerConnection<class_WebRTCPeerConnection>`, :ref:`XMLParser<class_XMLParser>`, :ref:`XRInterface<class_XRInterface>`, :ref:`XRPose<class_XRPose>`, :ref:`XRPositionalTracker<class_XRPositionalTracker>`
|
|
|
|
Base class for reference-counted objects.
|
|
|
|
Description
|
|
-----------
|
|
|
|
Base class for any object that keeps a reference count. :ref:`Resource<class_Resource>` and many other helper objects inherit this class.
|
|
|
|
Unlike other :ref:`Object<class_Object>` types, ``RefCounted``\ s keep an internal reference counter so that they are automatically released when no longer in use, and only then. ``RefCounted``\ s therefore do not need to be freed manually with :ref:`Object.free<class_Object_method_free>`.
|
|
|
|
In the vast majority of use cases, instantiating and using ``RefCounted``-derived types is all you need to do. The methods provided in this class are only for advanced users, and can cause issues if misused.
|
|
|
|
\ **Note:** In C#, reference-counted objects will not be freed instantly after they are no longer in use. Instead, garbage collection will run periodically and will free reference-counted objects that are no longer in use. This means that unused ones will linger on for a while before being removed.
|
|
|
|
Tutorials
|
|
---------
|
|
|
|
- :doc:`When and how to avoid using nodes for everything <../tutorials/best_practices/node_alternatives>`
|
|
|
|
Methods
|
|
-------
|
|
|
|
+-------------------------+---------------------------------------------------------------------------------------------+
|
|
| :ref:`int<class_int>` | :ref:`get_reference_count<class_RefCounted_method_get_reference_count>` **(** **)** |const| |
|
|
+-------------------------+---------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`init_ref<class_RefCounted_method_init_ref>` **(** **)** |
|
|
+-------------------------+---------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`reference<class_RefCounted_method_reference>` **(** **)** |
|
|
+-------------------------+---------------------------------------------------------------------------------------------+
|
|
| :ref:`bool<class_bool>` | :ref:`unreference<class_RefCounted_method_unreference>` **(** **)** |
|
|
+-------------------------+---------------------------------------------------------------------------------------------+
|
|
|
|
Method Descriptions
|
|
-------------------
|
|
|
|
.. _class_RefCounted_method_get_reference_count:
|
|
|
|
- :ref:`int<class_int>` **get_reference_count** **(** **)** |const|
|
|
|
|
Returns the current reference count.
|
|
|
|
----
|
|
|
|
.. _class_RefCounted_method_init_ref:
|
|
|
|
- :ref:`bool<class_bool>` **init_ref** **(** **)**
|
|
|
|
Initializes the internal reference counter. Use this only if you really know what you are doing.
|
|
|
|
Returns whether the initialization was successful.
|
|
|
|
----
|
|
|
|
.. _class_RefCounted_method_reference:
|
|
|
|
- :ref:`bool<class_bool>` **reference** **(** **)**
|
|
|
|
Increments the internal reference counter. Use this only if you really know what you are doing.
|
|
|
|
Returns ``true`` if the increment was successful, ``false`` otherwise.
|
|
|
|
----
|
|
|
|
.. _class_RefCounted_method_unreference:
|
|
|
|
- :ref:`bool<class_bool>` **unreference** **(** **)**
|
|
|
|
Decrements the internal reference counter. Use this only if you really know what you are doing.
|
|
|
|
Returns ``true`` if the decrement was successful, ``false`` otherwise.
|
|
|
|
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
|
|
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
|
|
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
|
|
.. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
|
|
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
|
|
.. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
|