j2me: Singleton Data Objects?

B

Bjoern

Hi,

Naturally I want to store my Data in the RecordStore, and now I've
created a Management Class that either creates a new Data Object from
the Data in the RecordStore, or hands out a new reference if an instance
already exists. I guess I implemented a sort of Object Pool, and each
Object has a counter that keeps track of how many references of an
Object are in use.

Except of course it only works as long as the new references are only
created via the proper methods, and destroy() (which decreases the
counter) is called to dispose of Objects. But I totally forgot that
maybe a referenc ecould be copied directly, which would totally break my
scheme.

Now I wonder if this is still OK, as I guess there is no way around it?
I guess it's a problem all ObjectPools face, what to do with an Object
that has officially been returned to the pool, but is still used
somewhere. Or objects that never get returned to the Pool. What else can
be done, besides counting on the developer to treat it with care? It
seems there is no way to access the virtual machines counter of
references to an object :-(

I suppose I could implement a sort of isValid flag, but somehow I don't
like the idea of including a check for that in every method call of the
object.

Any other ideas?

Many thanks


Bjoern


--


Let's not weep for their evil deeds,
but for their lack of imagination
(Nick Cave)
 

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

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top