Browse Source

Add missing `dispose()` methods (#21577)

* Add missing `dispose()` methods for AxesHelper and CameraHelper

* Add missing `dispose()` methods for Light and LightShadow

* Add `dispose()` to docs for AxesHelper and CameraHelper

* Add `dispose()` to docs for Lights and LightShadow

* Fix eslint issues

* Replace spaces with tabs in documentation
Ryan Henning 4 years ago
parent
commit
1bbe806627

+ 5 - 0
docs/api/en/helpers/AxesHelper.html

@@ -44,6 +44,11 @@ scene.add( axesHelper );
 		<h2>Methods</h2>
 		<p>See the base [page:LineSegments] class for common methods.</p>
 
+		<h3>[method:AxesHelper dispose]()</h3>
+		<p>
+		Disposes of the internally-created [page:Line.material material] and [page:Line.geometry geometry] used by this helper.
+		</p>
+
 		<h2>Source</h2>
 
 		<p>

+ 4 - 0
docs/api/en/helpers/CameraHelper.html

@@ -68,6 +68,10 @@ scene.add( helper );
 		<h2>Methods</h2>
 		<p>See the base [page:LineSegments] class for common methods.</p>
 
+		<h3>[method:CameraHelper dispose]()</h3>
+		<p>
+		Disposes of the internally-created [page:Line.material material] and [page:Line.geometry geometry] used by this helper.
+		</p>
 
 		<h3>[method:null update]()</h3>
 		<p>Updates the helper based on the projectionMatrix of the camera.</p>

+ 6 - 0
docs/api/en/lights/DirectionalLight.html

@@ -117,6 +117,12 @@
 
 		<p>See the base [page:Light Light] class for common methods.</p>
 
+		<h3>[method:DirectionalLight dispose]()</h3>
+		<p>
+		Override of base class's [page:Light.dispose dispose].
+		Disposes of this light's [page:DirectionalLightShadow shadow].
+		</p>
+
 		<h3>[method:DirectionalLight copy]( [param:DirectionalLight source] )</h3>
 		<p>
 		Copies value of all the properties from the [page:DirectionalLight source] to this

+ 4 - 0
docs/api/en/lights/Light.html

@@ -52,6 +52,10 @@
 			See the base [page:Object3D Object3D] class for common methods.
 		</p>
 
+		<h3>[method:Light dispose]()</h3>
+		<p>
+		Abstract dispose method for lights; implemented by subclasses that have disposable resources.
+		</p>
 
 		<h3>[method:Light copy]( [param:Light source] )</h3>
 		<p>

+ 6 - 0
docs/api/en/lights/PointLight.html

@@ -105,6 +105,12 @@ scene.add( light );
 			See the base [page:Light Light] class for common methods.
 		</p>
 
+		<h3>[method:PointLight dispose]()</h3>
+		<p>
+		Override of base class's [page:Light.dispose dispose].
+		Disposes of this light's [page:PointLightShadow shadow].
+		</p>
+
 		<h3>[method:PointLight copy]( [param:PointLight source] )</h3>
 		<p>
 		Copies value of all the properties from the [page:PointLight source] to this

+ 6 - 0
docs/api/en/lights/SpotLight.html

@@ -163,6 +163,12 @@ light.target = targetObject;
 
 		<p>See the base [page:Light Light] class for common methods.</p>
 
+		<h3>[method:SpotLight dispose]()</h3>
+		<p>
+		Override of base class's [page:Light.dispose dispose].
+		Disposes of this light's [page:SpotLightShadow shadow].
+		</p>
+
 		<h3>[method:SpotLight copy]( [param:SpotLight source] )</h3>
 		<p>
 		Copies value of all the properties from the [page:SpotLight source] to this

+ 5 - 0
docs/api/en/lights/shadows/LightShadow.html

@@ -122,6 +122,11 @@
 		Used internally by the renderer to get the number of viewports that need to be rendered for this shadow.
 		</p>
 
+		<h3>[method:LightShadow dispose]()</h3>
+		<p>
+		Disposes of this shadow's textures ([page:LightShadow.map map] and [page:LightShadow.mapPass mapPass]).
+		</p>
+
 		<h3>[method:LightShadow copy]( [param:LightShadow source] )</h3>
 		<p>
 		Copies value of all the properties from the [page:LightShadow source] to this

+ 7 - 0
src/helpers/AxesHelper.js

@@ -31,6 +31,13 @@ class AxesHelper extends LineSegments {
 
 	}
 
+	dispose() {
+
+		this.geometry.dispose();
+		this.material.dispose();
+
+	}
+
 }
 
 

+ 7 - 0
src/helpers/CameraHelper.js

@@ -177,6 +177,13 @@ class CameraHelper extends LineSegments {
 
 	}
 
+	dispose() {
+
+		this.geometry.dispose();
+		this.material.dispose();
+
+	}
+
 }
 
 

+ 6 - 0
src/lights/DirectionalLight.js

@@ -19,6 +19,12 @@ class DirectionalLight extends Light {
 
 	}
 
+	dispose() {
+
+		this.shadow.dispose();
+
+	}
+
 	copy( source ) {
 
 		super.copy( source );

+ 6 - 0
src/lights/Light.js

@@ -14,6 +14,12 @@ class Light extends Object3D {
 
 	}
 
+	dispose() {
+
+		// Empty here in base class; some subclasses override.
+
+	}
+
 	copy( source ) {
 
 		super.copy( source );

+ 16 - 0
src/lights/LightShadow.js

@@ -91,6 +91,22 @@ class LightShadow {
 
 	}
 
+	dispose() {
+
+		if ( this.map ) {
+
+			this.map.dispose();
+
+		}
+
+		if ( this.mapPass ) {
+
+			this.mapPass.dispose();
+
+		}
+
+	}
+
 	copy( source ) {
 
 		this.camera = source.camera.clone();

+ 6 - 0
src/lights/PointLight.js

@@ -32,6 +32,12 @@ class PointLight extends Light {
 
 	}
 
+	dispose() {
+
+		this.shadow.dispose();
+
+	}
+
 	copy( source ) {
 
 		super.copy( source );

+ 6 - 0
src/lights/SpotLight.js

@@ -40,6 +40,12 @@ class SpotLight extends Light {
 
 	}
 
+	dispose() {
+
+		this.shadow.dispose();
+
+	}
+
 	copy( source ) {
 
 		super.copy( source );