Hey!
I'm working on a javascript project which will run on a single html page, and I'm using lots of objects. The program will create new instances of these objects during runtime. However, for efficiency, I need a way to get rid of the old ones. Is there any way to do this?
8 2282
by objects you mean elements?
any html element can be cleared with the innerHTML() method. Just set it to an empty string.
Ach, I'm sorry, I meant this sort of object -
function spaceShip(hull, shields, weapons)
-
{
-
this.hull = hull;
-
this.shields = shields;
-
this.weapons = weapons;
-
this.crew = 5;
-
}
-
var nightHawk = new spaceShip("Titanium", 16, phasers);
-
I'm not sure what it is called, but I was wondering how to remove instances of such an object.
If you declare your objects as globals with the var keyword, as in your example, you cannot delete them. The nearest you can get is to set them to undefined.
Oh dear. That is a bit of a bummer. What if instead I put them in an array, like this? -
var fleet = new Array(3);
-
fleet[0] = new spaceShip("Iron", 9, phasers);
-
fleet[1] = new spaceShip("Titanium", 13, phasers);
-
fleet[2] = new spaceShip("Aluminum", 2, phasers);
-
fleet.splice(1,1);
-
When splice is run, would the object be removed then? Or would it just be floating around somewhere?
Object removing means .. you want to say your JS Engine to free up the memory(occupied by an instance) when the object no longer needed.
Did you mean that?
Yeah, thats what I meant.
Awesome! Thank you very much.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: koperenkogel |
last post by:
Dear cpp-ians,
I am working with a vector of structures.
vector <meta_segment> meta_segm (2421500);
and the structure look like:
struct meta_segment
{
float id;
float num;
|
by: u7djo |
last post by:
Hi,
I'm currently building an application in Access and as part of this
need to import forms and modules from another database. Some of the
imports will be revisions of existing forms/modules so I...
|
by: Franck Diastein |
last post by:
Hi, I'm trying to remove items from a collection this way:
foreach(Object myO in ObjectCol){
if(myO != "xxx"){
myO.Remove();
}
}
But I'm having an error telling me that Collection was...
|
by: Jonathan |
last post by:
Hi. I'm having trouble figuring out what I should be doing here.
I'm trying to remove an object from a list.
The function is:
void Alive::FromRoom ()
{
list<Alive>::iterator iter =...
|
by: pamelafluente |
last post by:
Hi
I have a sorted list with several thousands items. In my case, but this
is not important, objects are stored only in Keys, Values are all
Nothing. Several of the stored objects (might be a...
|
by: ken |
last post by:
How to remove specified cookie (via a given name) in cookie jar?
I have the following code, but how can I remove a specified cookie in
the cookie jar?
cj = cookielib.LWPCookieJar()
if cj is...
|
by: Richard Maher |
last post by:
Hi,
I have read many of the copius entries on the subject of IE performance (or
the lack thereof) when populating Select Lists.
I don't mind the insert performance so much, (I get 100x120byte...
|
by: =?Utf-8?B?emhhbmdscg==?= |
last post by:
Hi,
Following code does not work. (it will crash.)-- I think the reason is that
I cannot modify list (call remove) in foreach. But I don't know what I can
do.
...
|
by: news |
last post by:
Well here's a sample of the code:
class someobject{};
ArrayList alist;
alist = new ArrayList();
for(int i = 0; i<10;++i)
alist.Add(new someobject());
|
by: Rainer Queck |
last post by:
Hello NG,
is it possible to use linq to remove certain objects from a generic list?
Something more or less like:
from obj in MyList
where obj.Id 25
delete obj
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |