Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CREATE and DESTROY in an event

162 views
Skip to first unread message

Gord

unread,
Oct 5, 2000, 3:00:00 AM10/5/00
to
Just a bit of confusion I'm hoping someone can clear up.

In an event/function, if I create a user object local to the script (and
user object is not autoinstantiated), do I have to destroy it, or does
Powerbuilder(6.5/7.0) do that for me at some point in time.

eg:

uo_datastore lds_DataStore
lds_datastore = Create uo_datastore
...

Destroy lds_DataStore (must I do this?)

I'm just having a blonde day, and I've got myself confused!

Gord

Bill Green[TeamSybase]

unread,
Oct 5, 2000, 3:00:00 AM10/5/00
to
For most objects, PB will clean up, but for some objects (like datastores),
you must destroy or you will introduce a memory leak.

regards,
Bill

Gord wrote:

--
Bill Green[TeamSybase]
-----------------------------------------------------------
Good Links to know, good places to go:

News: Sybase Portal is live - Go http://my.sybase.com

Developer stuff on my.sybase.com
Find things like:
-- EAServer 3.6 maintenance release is available
-- PowerBuilder C3 maintenance release available (build 8046)
-- Components, White papers, articles and more
-- Web DataWindow Article Series (Author: Larry Cermak)
-- Jaguar Agent for Web Servers (HTTP access to PB components)

PFC Guide - http://www.pfcguide.com

Power3 - Custom Training - http://www.power3.com
Bill Green @ Power3 - wgr...@power3.com
-----------------------------------------------------------

Simon Caldwell

unread,
Oct 6, 2000, 3:00:00 AM10/6/00
to
Are you sure about that? The online help for DESTROY says
"When you are finished with an object that you created, you can call DESTROY
to release its memory. However, you should only call DESTROY if you are sure
that the object is not referenced by any other object. PowerBuilder's
garbage collection mechanism maintains a count of references to each object
and destroys unreferenced objects automatically"

S.

--
Simon Caldwell
Get Real Systems Ltd
Holtby Manor, Stamford Bridge Road, York, YO19 5LL
Tel 01904 481999 Fax 01904 481666
Visit us at www.getrealsystems.com

Specialists in e-Procurement and supply chain technology


"Bill Green[TeamSybase]" <bill....@teamsybase.com> wrote in message
news:39DCDCB0...@teamsybase.com...

Philip Salgannik

unread,
Oct 6, 2000, 3:00:00 AM10/6/00
to
Where is the contradiction?

--
This is a FAQ, read Help, then search www.deja.com

pbm_thisusuallydoesnothelp:-))

Philip Salgannik


"Simon Caldwell" <simonDOTcaldwellATgetrealsystemsDOTcom> wrote in message
news:qOcaZF4...@forums.sybase.com...

Bill Green[TeamSybase]

unread,
Oct 6, 2000, 3:00:00 AM10/6/00
to
Correct, but the datastore object maintains a reference to it's dataobject (and
the dataobject to the datastore) so the garbage collector thinks it's still
active.

Bill

Jerry Siegel

unread,
Oct 6, 2000, 3:00:00 AM10/6/00
to
It is good practice to Destroy what you have Created when it is no longer
needed, rather than rely on the garbage collector.

Gord wrote in message ...

Simon Caldwell

unread,
Oct 9, 2000, 3:00:00 AM10/9/00
to
Bill's post says (probably correctly) that you need to destroy datastores
explicitly. The online help says this is not necessary.
FWIW I always destroy what I have created, it's safer and IMHO better
programming style.
S.


"Philip Salgannik" <psalg...@softrax.com> wrote in message
news:9$#34P6LA...@forums.sybase.com...


> Where is the contradiction?
>
> --
> This is a FAQ, read Help, then search www.deja.com
>
> pbm_thisusuallydoesnothelp:-))
>
> Philip Salgannik
>
>
> "Simon Caldwell" <simonDOTcaldwellATgetrealsystemsDOTcom> wrote in message
> news:qOcaZF4...@forums.sybase.com...

> > > > Just a bit of confusion I'm hoping someone can clear up.
> > > >
> > > > In an event/function, if I create a user object local to the script
> (and
> > > > user object is not autoinstantiated), do I have to destroy it, or
does
> > > > Powerbuilder(6.5/7.0) do that for me at some point in time.
> > > >
> > > > eg:
> > > >
> > > > uo_datastore lds_DataStore
> > > > lds_datastore = Create uo_datastore
> > > > ...
> > > >
> > > > Destroy lds_DataStore (must I do this?)
> > > >
> > > > I'm just having a blonde day, and I've got myself confused!
> > > >
> > > > Gord
> > >

Jerry Siegel

unread,
Oct 9, 2000, 3:00:00 AM10/9/00
to
<choir>Amen!</choir>

Simon Caldwell wrote in message ...

John De Lelllo

unread,
Oct 9, 2000, 3:00:00 AM10/9/00
to
I agree with Simon about not relying on the GC to clean up after you.
However, if a programmer is coming to PB from Java, then they might have a
different view since Java does not have a Destroy function.

--
John De Lello
DelWare Consulting Group
Programming solutions for today's complex problems
http://www.DelWare.com

"Jerry Siegel" <jer...@data-sci.com.NOSPAM> wrote in message
news:II8DSZf...@forums.sybase.com...

Sybase Forums

unread,
Oct 9, 2000, 3:00:00 AM10/9/00
to
If you manually create using a create statement you should destroy it when
you are done.


"John De Lelllo" <Jo...@DelWare.com> wrote in message
news:5BFABCg...@forums.sybase.com...

Simon Caldwell

unread,
Oct 10, 2000, 3:00:00 AM10/10/00
to
...despite the advice to the contrary given in the online help?!?


"Sybase Forums" <t...@systemsevolution.com> wrote in message
news:qF1tB3g...@forums.sybase.com...

Glenn Santa Cruz

unread,
Oct 12, 2000, 3:00:00 AM10/12/00
to
Bill,

Taking this one step further, does this imply that PB components which
have methods that return ResultSets will constantly leak? Given this
(poorly written) sample:

<--------------------------------
datastore lds_foo
lds_foo = create datastore
lds_foo.dataobject = 'd_foo'
lds_foo.setTransObject( sqlca )

lds_foo.retrieve("somearg")

ResultSet lrs_results
lds_foo.GenerateResultSet( lrs_results )

return lrs_results
<--------------------------------

I can't destroy the datastore before returning the RS, since the RS
maintains a reference to it. Hence, leakage on every single call to
this method? Is the solution to use an instance datastore, relying on
Deactivate to destroy?

Glenn


"Bill Green[TeamSybase]" wrote:
>
> Correct, but the datastore object maintains a reference to it's dataobject (and
> the dataobject to the datastore) so the garbage collector thinks it's still
> active.
>
> Bill
>
> Simon Caldwell wrote:
>

Bill Green[TeamSybase]

unread,
Oct 13, 2000, 3:00:00 AM10/13/00
to
IN a 2-tier client-server environment, yes. In an EAServer environment you have other
options available which will help perform cleanup, especially when components get
pooled etc. So, in answer to your question, yes, you would either code a destroy in
your deactivate event (using an instance variable), or, if the component were
auto-demarcated, Jaguar would take care of cleanup for you, or if your code called
setComplete() somewhere, forcing demarcation, then again, Jag helps you out.

But in the 2-tier world, there is no server to help you, so if you do not clean up,
you will leak.


regards,
Bill

0 new messages