Should I use OO?

T

Tim

I need some advice on how to approach a certain scenario, I have a
grid in which I will be adding and removing rows dynamically, I am
unsure if I should create rows as objects or just simply build the DOM
structure and append it?

I would prefer to go the OO route, but my main concern is creating
hundreds of instances of a object just floating around in memory. As
far as I know there is no way to destroy instances, so once a row is
removed the instance still exists, I don't know how garbage collection
works in modern browsers so maybe this isn't an issue.

I guess my real question is; do multiple instances take up memory or
slow the CPU?

Thanks
 
B

Bart Van der Donck

Tim said:
I need some advice on how to approach a certain scenario, I have a
grid in which I will be adding and removing rows dynamically, I am
unsure if I should create rows as objects or just simply build the DOM
structure and append it?

I'm not sure why you make such a black/white distinction; actually the
DOM is an OO-based structure too. Working with the DOM is already
working in an object-oriented environment. At first sight, I would
approach the parent <table> in order to play with its <tr>'s; no
further creation of objects is needed then. I would not go
"duplicating" the existing DOM by creating a bunch of new stuff.

But maybe your scenario is more complex than that.
I would prefer to go the OO route, but my main concern is creating
hundreds of instances of a object just floating around in memory.

This can be a problem, yes. But I tend to think that a few hundreds
should normally be okay - if they're not too heavy.
As far as I know there is no way to destroy instances, so once a row
is removed the instance still exists, I don't know how garbage
collection works in modern browsers so maybe this isn't an issue.

The javascript programmer can only "hope" that the browser collects
the garbage decently (which is, in my experience, mostly okay). See my
earlier article:
http://groups.google.com/group/comp.lang.javascript/msg/fe3c7c11f20ad185/
I guess my real question is; do multiple instances take up memory
or slow the CPU?

Yes they do - by definition. For such an application, I would first
benchmark the memory performances on different browsers/platforms to
see whether it's acceptable or not.

Hope this helps,
 
T

Tim

I'm not sure why you make such a black/white distinction; actually the
DOM is an OO-based structure too. Working with the DOM is already
working in an object-oriented environment. At first sight, I would
approach the parent <table> in order to play with its <tr>'s; no
further creation of objects is needed then. I would not go
"duplicating" the existing DOM by creating a bunch of new stuff.

But maybe your scenario is more complex than that.


This can be a problem, yes. But I tend to think that a few hundreds
should normally be okay - if they're not too heavy.


The javascript programmer can only "hope" that the browser collects
the garbage decently (which is, in my experience, mostly okay). See my
earlier article:http://groups.google.com/group/comp.lang.javascript/msg/fe3c7c11f20ad...


Yes they do - by definition. For such an application, I would first
benchmark the memory performances on different browsers/platforms to
see whether it's acceptable or not.

Hope this helps,

Thanks a lot, that was everything I needed to know. I think I'll take
your advice and test it out to monitor the memory performance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top