BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

SpotLight.dispose()

The dispose() method of the SpotLight class in the Three.js library is used to free the memory used by the spotlight object. It removes the spotlight from the scene, clears its references and disposes all of its internal resources.

Syntax

spotlight.dispose();

Parameters

None.

Return Value

None.

Description

The SpotLight class implements a spotlight that illuminates the scene with a cone of light that radiates from a point in a specific direction. The spotlight needs to be added to the scene using the add() method, and can be removed using the remove() method.

When a spotlight is no longer needed, it should be disposed of using the dispose() method. This method removes the spotlight from the scene, clears its references and disposes all of its internal resources. This frees up the memory used by the spotlight object and ensures that there are no memory leaks or performance issues.

Examples

const scene = new THREE.Scene();

const spotlight = new THREE.SpotLight(0xffffff, 1, 100, Math.PI / 4, 0.6);
spotlight.position.set(1, 0, 0);
scene.add(spotlight);

// ... rendering and animation code ...

// When the spotlight is no longer needed, dispose of it.
spotlight.dispose();

In the above example, a SpotLight object is created and added to the scene using the add() method. When the spotlight is no longer needed, it is disposed of using the dispose() method.

Remarks

  • Disposing a spotlight will not remove any references to it in other objects or variables. It is the responsibility of the developer to ensure that all references to the spotlight are removed.

  • Disposing a spotlight will also dispose of any associated shadows that were created using the SpotLightShadow class.

  • It is not necessary to dispose of a spotlight if it is removed from the scene using the remove() method.

See Also