You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Jesse Pelton <js...@PKC.com> on 2000/07/25 16:19:05 UTC

RE: RE: RE: Re: memory leaks in XMLPlatformUtils::Initialize() (v .1.0 .1)

We're developing a toolkit for other developers to use.  This toolkit will
produce and consume XML documents (among other functions).  I don't think
our environment affects the problems we're having, but for the record, it's
Windows 2000, MSVC 6.0 SP3, using a statically linked version of Xerces-C
1.2.0a.  Following is a message from the lead developer on the toolkit.  I'd
appreciate any responses.  (We know that Terminate() is currently optional,
but it may not always be.  Besides, we are more comfortable when such calls
are balanced.)

I know of at least two situations where using a Boolean initialization in
the XML library Initialize() and Terminate() Api's is a problem. The first
has to do with a software development environment in which one is developing
a set of classes to be put into a library for use by others. More than one
of these classes might need to initialize the XML library. You would like to
design the classes so that the consumer of the classes does not have to have
any knowledge of the XML library. If you have only one of these classes, it
can, of course, initialize the library and terminate the library as it
requires. However, if instances of more than one of these classes exist,
they might both initialize the library. This is fine "going in" given the
current implementation of the XML library, because there is a static flag
which prevents the library from being initialized more than once. However,
upon termination, whichever object terminates the library first wins. The
second object loses, because it still needs the XML library, which has been
terminated by the other object. Note that this can also happen if an object
which needs to initialize the XML library does so, while its containing
application initializes it as well.

In the second case, in a multi-threaded application, the XML library may be
needed in more than one thread. In this case one thread may terminate the
XML library while it is still needed by another thread. Once again, the
second thread loses.

The solution is, I believe, to take the global boolean gInit flag and turn
it into a reference count. When Initialize() is called the first time, the
library is initialized and the reference counter is set to '1.' It is useful
as well for the caller to have the reference count returned by Initialize
(), so it knows whether the library was already initialized or not. On
subsequent calls, the library is not initialized, but the reference counter
is incremented.

In the Terminate method, likewise, the reference counter is decremented.
When the reference count reaches zero, the library is actually Terminated.
Likewise, it is useful for the caller to have the reference count returned,
so it knows whether the library was actually terminated or not.

Jesse Pelton
PKC Corporation

Re: RE: RE: Re: memory leaks in XMLPlatformUtils::Initialize() (v.1.0 .1)

Posted by Dean Roddey <dr...@charmedquark.com>.
I don't disagree with that assessment. We were really trying to have to get
into having to bootstrap ourselves in a multi-threaded environment, because
that means we have to insure that we have synchronization before we are
bootstrapped, in order to synchronize our bootstrap, etc... It can be done,
and we can compare and swap in a platform mutex, and that was discussed. If
we end up making such a change, that would probably be the way to go. We
would just have a BaseLock class which is a magic janitor for a singleton
compare/swapped-in platform mutex that we can use for the fundamental
synchronization required to get ourselves kicked in and ref count the init
flag.

--------------------------
Dean Roddey
The CIDLib C++ Frameworks
Charmed Quark Software
droddey@charmedquark.com
http://www.charmedquark.com

"You young, and you gotcha health. Whatchoo wanna job fer?"


----- Original Message -----
From: "Jesse Pelton" <js...@PKC.com>
To: <xe...@xml.apache.org>
Sent: Tuesday, July 25, 2000 7:19 AM
Subject: RE: RE: RE: Re: memory leaks in XMLPlatformUtils::Initialize()
(v.1.0 .1)


> We're developing a toolkit for other developers to use.  This toolkit will
> produce and consume XML documents (among other functions).  I don't think
> our environment affects the problems we're having, but for the record,
it's
> Windows 2000, MSVC 6.0 SP3, using a statically linked version of Xerces-C
> 1.2.0a.  Following is a message from the lead developer on the toolkit.
I'd
> appreciate any responses.  (We know that Terminate() is currently
optional,
> but it may not always be.  Besides, we are more comfortable when such
calls
> are balanced.)
>
> I know of at least two situations where using a Boolean initialization in
> the XML library Initialize() and Terminate() Api's is a problem. The first
> has to do with a software development environment in which one is
developing
> a set of classes to be put into a library for use by others. More than one
> of these classes might need to initialize the XML library. You would like
to
> design the classes so that the consumer of the classes does not have to
have
> any knowledge of the XML library. If you have only one of these classes,
it
> can, of course, initialize the library and terminate the library as it
> requires. However, if instances of more than one of these classes exist,
> they might both initialize the library. This is fine "going in" given the
> current implementation of the XML library, because there is a static flag
> which prevents the library from being initialized more than once. However,
> upon termination, whichever object terminates the library first wins. The
> second object loses, because it still needs the XML library, which has
been
> terminated by the other object. Note that this can also happen if an
object
> which needs to initialize the XML library does so, while its containing
> application initializes it as well.
>
> In the second case, in a multi-threaded application, the XML library may
be
> needed in more than one thread. In this case one thread may terminate the
> XML library while it is still needed by another thread. Once again, the
> second thread loses.
>
> The solution is, I believe, to take the global boolean gInit flag and turn
> it into a reference count. When Initialize() is called the first time, the
> library is initialized and the reference counter is set to '1.' It is
useful
> as well for the caller to have the reference count returned by Initialize
> (), so it knows whether the library was already initialized or not. On
> subsequent calls, the library is not initialized, but the reference
counter
> is incremented.
>
> In the Terminate method, likewise, the reference counter is decremented.
> When the reference count reaches zero, the library is actually Terminated.
> Likewise, it is useful for the caller to have the reference count
returned,
> so it knows whether the library was actually terminated or not.
>
> Jesse Pelton
> PKC Corporation
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>


Re: memory leaks in XMLPlatformUtils::Initialize() (v.1.0 .1)

Posted by James Berry <jb...@criticalpath.com>.
This proposal sounds fine from the Mac side. I assume the reference count
would be implemented using the atomic routines.

-jdb

Andy Heninger wrote:

> This proposal sounds reasonable to me.
> If no one as any strong objections, I think that we should go ahead and do
> it.
>
> Note that it doesn't address the other initialize/terminate problem, which
> is that once terminated, Xerces can not be re-initialized.  Fixing this
> (and having any confidence that the re-initialization will be reliable)
> would be much harder.
>
> Andy Heninger
> IBM XML Technology Group, Cupertino, CA
> heninger@us.ibm.com
>
> ----- Original Message -----
> From: "Jesse Pelton" <js...@PKC.com>
> To: <xe...@xml.apache.org>
> Sent: Tuesday, July 25, 2000 7:19 AM
> Subject: RE: RE: RE: Re: memory leaks in XMLPlatformUtils::Initialize()
> (v.1.0 .1)
>
> > We're developing a toolkit for other developers to use.  This toolkit
> will
> > produce and consume XML documents (among other functions).  I don't
> think
> > our environment affects the problems we're having, but for the record,
> it's
> > Windows 2000, MSVC 6.0 SP3, using a statically linked version of
> Xerces-C
> > 1.2.0a.  Following is a message from the lead developer on the toolkit.
> I'd
> > appreciate any responses.  (We know that Terminate() is currently
> optional,
> > but it may not always be.  Besides, we are more comfortable when such
> calls
> > are balanced.)
> >
> > I know of at least two situations where using a Boolean initialization
> in
> > the XML library Initialize() and Terminate() Api's is a problem. The
> first
> > has to do with a software development environment in which one is
> developing
> > a set of classes to be put into a library for use by others. More than
> one
> > of these classes might need to initialize the XML library. You would
> like to
> > design the classes so that the consumer of the classes does not have to
> have
> > any knowledge of the XML library. If you have only one of these classes,
> it
> > can, of course, initialize the library and terminate the library as it
> > requires. However, if instances of more than one of these classes exist,
> > they might both initialize the library. This is fine "going in" given
> the
> > current implementation of the XML library, because there is a static
> flag
> > which prevents the library from being initialized more than once.
> However,
> > upon termination, whichever object terminates the library first wins.
> The
> > second object loses, because it still needs the XML library, which has
> been
> > terminated by the other object. Note that this can also happen if an
> object
> > which needs to initialize the XML library does so, while its containing
> > application initializes it as well.
> >
> > In the second case, in a multi-threaded application, the XML library may
> be
> > needed in more than one thread. In this case one thread may terminate
> the
> > XML library while it is still needed by another thread. Once again, the
> > second thread loses.
> >
> > The solution is, I believe, to take the global boolean gInit flag and
> turn
> > it into a reference count. When Initialize() is called the first time,
> the
> > library is initialized and the reference counter is set to '1.' It is
> useful
> > as well for the caller to have the reference count returned by
> Initialize
> > (), so it knows whether the library was already initialized or not. On
> > subsequent calls, the library is not initialized, but the reference
> counter
> > is incremented.
> >
> > In the Terminate method, likewise, the reference counter is decremented.
> > When the reference count reaches zero, the library is actually
> Terminated.
> > Likewise, it is useful for the caller to have the reference count
> returned,
> > so it knows whether the library was actually terminated or not.
> >
> > Jesse Pelton
> > PKC Corporation
> >


Re: RE: RE: Re: memory leaks in XMLPlatformUtils::Initialize() (v.1.0 .1)

Posted by Dean Roddey <dr...@charmedquark.com>.
Yeh, the re-init will be tricky and error prone.

--------------------------
Dean Roddey
The CIDLib C++ Frameworks
Charmed Quark Software
droddey@charmedquark.com
http://www.charmedquark.com

"You young, and you gotcha health. Whatchoo wanna job fer?"


----- Original Message -----
From: "Andy Heninger" <an...@jtcsv.com>
To: <xe...@xml.apache.org>
Sent: Tuesday, July 25, 2000 11:48 AM
Subject: Re: RE: RE: Re: memory leaks in XMLPlatformUtils::Initialize()
(v.1.0 .1)


> This proposal sounds reasonable to me.
> If no one as any strong objections, I think that we should go ahead and do
> it.
>
> Note that it doesn't address the other initialize/terminate problem, which
> is that once terminated, Xerces can not be re-initialized.  Fixing this
> (and having any confidence that the re-initialization will be reliable)
> would be much harder.
>
> Andy Heninger
> IBM XML Technology Group, Cupertino, CA
> heninger@us.ibm.com
>
>
> ----- Original Message -----
> From: "Jesse Pelton" <js...@PKC.com>
> To: <xe...@xml.apache.org>
> Sent: Tuesday, July 25, 2000 7:19 AM
> Subject: RE: RE: RE: Re: memory leaks in XMLPlatformUtils::Initialize()
> (v.1.0 .1)
>
>
> > We're developing a toolkit for other developers to use.  This toolkit
> will
> > produce and consume XML documents (among other functions).  I don't
> think
> > our environment affects the problems we're having, but for the record,
> it's
> > Windows 2000, MSVC 6.0 SP3, using a statically linked version of
> Xerces-C
> > 1.2.0a.  Following is a message from the lead developer on the toolkit.
> I'd
> > appreciate any responses.  (We know that Terminate() is currently
> optional,
> > but it may not always be.  Besides, we are more comfortable when such
> calls
> > are balanced.)
> >
> > I know of at least two situations where using a Boolean initialization
> in
> > the XML library Initialize() and Terminate() Api's is a problem. The
> first
> > has to do with a software development environment in which one is
> developing
> > a set of classes to be put into a library for use by others. More than
> one
> > of these classes might need to initialize the XML library. You would
> like to
> > design the classes so that the consumer of the classes does not have to
> have
> > any knowledge of the XML library. If you have only one of these classes,
> it
> > can, of course, initialize the library and terminate the library as it
> > requires. However, if instances of more than one of these classes exist,
> > they might both initialize the library. This is fine "going in" given
> the
> > current implementation of the XML library, because there is a static
> flag
> > which prevents the library from being initialized more than once.
> However,
> > upon termination, whichever object terminates the library first wins.
> The
> > second object loses, because it still needs the XML library, which has
> been
> > terminated by the other object. Note that this can also happen if an
> object
> > which needs to initialize the XML library does so, while its containing
> > application initializes it as well.
> >
> > In the second case, in a multi-threaded application, the XML library may
> be
> > needed in more than one thread. In this case one thread may terminate
> the
> > XML library while it is still needed by another thread. Once again, the
> > second thread loses.
> >
> > The solution is, I believe, to take the global boolean gInit flag and
> turn
> > it into a reference count. When Initialize() is called the first time,
> the
> > library is initialized and the reference counter is set to '1.' It is
> useful
> > as well for the caller to have the reference count returned by
> Initialize
> > (), so it knows whether the library was already initialized or not. On
> > subsequent calls, the library is not initialized, but the reference
> counter
> > is incremented.
> >
> > In the Terminate method, likewise, the reference counter is decremented.
> > When the reference count reaches zero, the library is actually
> Terminated.
> > Likewise, it is useful for the caller to have the reference count
> returned,
> > so it knows whether the library was actually terminated or not.
> >
> > Jesse Pelton
> > PKC Corporation
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>


Re: RE: RE: Re: memory leaks in XMLPlatformUtils::Initialize() (v.1.0 .1)

Posted by Andy Heninger <an...@jtcsv.com>.
This proposal sounds reasonable to me.
If no one as any strong objections, I think that we should go ahead and do
it.

Note that it doesn't address the other initialize/terminate problem, which
is that once terminated, Xerces can not be re-initialized.  Fixing this
(and having any confidence that the re-initialization will be reliable)
would be much harder.

Andy Heninger
IBM XML Technology Group, Cupertino, CA
heninger@us.ibm.com


----- Original Message -----
From: "Jesse Pelton" <js...@PKC.com>
To: <xe...@xml.apache.org>
Sent: Tuesday, July 25, 2000 7:19 AM
Subject: RE: RE: RE: Re: memory leaks in XMLPlatformUtils::Initialize()
(v.1.0 .1)


> We're developing a toolkit for other developers to use.  This toolkit
will
> produce and consume XML documents (among other functions).  I don't
think
> our environment affects the problems we're having, but for the record,
it's
> Windows 2000, MSVC 6.0 SP3, using a statically linked version of
Xerces-C
> 1.2.0a.  Following is a message from the lead developer on the toolkit.
I'd
> appreciate any responses.  (We know that Terminate() is currently
optional,
> but it may not always be.  Besides, we are more comfortable when such
calls
> are balanced.)
>
> I know of at least two situations where using a Boolean initialization
in
> the XML library Initialize() and Terminate() Api's is a problem. The
first
> has to do with a software development environment in which one is
developing
> a set of classes to be put into a library for use by others. More than
one
> of these classes might need to initialize the XML library. You would
like to
> design the classes so that the consumer of the classes does not have to
have
> any knowledge of the XML library. If you have only one of these classes,
it
> can, of course, initialize the library and terminate the library as it
> requires. However, if instances of more than one of these classes exist,
> they might both initialize the library. This is fine "going in" given
the
> current implementation of the XML library, because there is a static
flag
> which prevents the library from being initialized more than once.
However,
> upon termination, whichever object terminates the library first wins.
The
> second object loses, because it still needs the XML library, which has
been
> terminated by the other object. Note that this can also happen if an
object
> which needs to initialize the XML library does so, while its containing
> application initializes it as well.
>
> In the second case, in a multi-threaded application, the XML library may
be
> needed in more than one thread. In this case one thread may terminate
the
> XML library while it is still needed by another thread. Once again, the
> second thread loses.
>
> The solution is, I believe, to take the global boolean gInit flag and
turn
> it into a reference count. When Initialize() is called the first time,
the
> library is initialized and the reference counter is set to '1.' It is
useful
> as well for the caller to have the reference count returned by
Initialize
> (), so it knows whether the library was already initialized or not. On
> subsequent calls, the library is not initialized, but the reference
counter
> is incremented.
>
> In the Terminate method, likewise, the reference counter is decremented.
> When the reference count reaches zero, the library is actually
Terminated.
> Likewise, it is useful for the caller to have the reference count
returned,
> so it knows whether the library was actually terminated or not.
>
> Jesse Pelton
> PKC Corporation
>



Re: RE: RE: Re: memory leaks in XMLPlatformUtils::Initialize() (v.1.0 .1)

Posted by Joe Polastre <jp...@apache.org>.
Well, I put in the change that you mentioned, Jesse.

I made gInitFlag a reference count to how many times Initialize() is called.
Then Terminate() will only do the termination routines after the init flag
returns back to zero (all processes that called Initialize() are now done
with the parser and have called Terminate())

This is the short term fix.  If you want to be able to call Init and Term
multiple times, someone is going to have to do a bit more work.

-Joe Polastre  (jpolast@apache.org)
IBM Cupertino, XML Technology Group


----- Original Message -----
From: "Jesse Pelton" <js...@PKC.com>
To: <xe...@xml.apache.org>
Sent: Tuesday, July 25, 2000 7:19 AM
Subject: RE: RE: RE: Re: memory leaks in XMLPlatformUtils::Initialize()
(v.1.0 .1)


> We're developing a toolkit for other developers to use.  This toolkit will
> produce and consume XML documents (among other functions).  I don't think
> our environment affects the problems we're having, but for the record,
it's
> Windows 2000, MSVC 6.0 SP3, using a statically linked version of Xerces-C
> 1.2.0a.  Following is a message from the lead developer on the toolkit.
I'd
> appreciate any responses.  (We know that Terminate() is currently
optional,
> but it may not always be.  Besides, we are more comfortable when such
calls
> are balanced.)
>
> I know of at least two situations where using a Boolean initialization in
> the XML library Initialize() and Terminate() Api's is a problem. The first
> has to do with a software development environment in which one is
developing
> a set of classes to be put into a library for use by others. More than one
> of these classes might need to initialize the XML library. You would like
to
> design the classes so that the consumer of the classes does not have to
have
> any knowledge of the XML library. If you have only one of these classes,
it
> can, of course, initialize the library and terminate the library as it
> requires. However, if instances of more than one of these classes exist,
> they might both initialize the library. This is fine "going in" given the
> current implementation of the XML library, because there is a static flag
> which prevents the library from being initialized more than once. However,
> upon termination, whichever object terminates the library first wins. The
> second object loses, because it still needs the XML library, which has
been
> terminated by the other object. Note that this can also happen if an
object
> which needs to initialize the XML library does so, while its containing
> application initializes it as well.
>
> In the second case, in a multi-threaded application, the XML library may
be
> needed in more than one thread. In this case one thread may terminate the
> XML library while it is still needed by another thread. Once again, the
> second thread loses.
>
> The solution is, I believe, to take the global boolean gInit flag and turn
> it into a reference count. When Initialize() is called the first time, the
> library is initialized and the reference counter is set to '1.' It is
useful
> as well for the caller to have the reference count returned by Initialize
> (), so it knows whether the library was already initialized or not. On
> subsequent calls, the library is not initialized, but the reference
counter
> is incremented.
>
> In the Terminate method, likewise, the reference counter is decremented.
> When the reference count reaches zero, the library is actually Terminated.
> Likewise, it is useful for the caller to have the reference count
returned,
> so it knows whether the library was actually terminated or not.
>
> Jesse Pelton
> PKC Corporation
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>