🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.windows.interviews
Article #1625

Resource life problem

#1625
From: Jason Scheck
Date: Wed, 06 Jan 1993 21:49
37 lines
1998 bytes
The idemo program contains the following line (it may have changed
since I grabbed the version I am using a few InterViews versions ago):

    main_ = new ApplicationWindow(
	new Background(
	    layout.vcenter(
		layout.vbox(
		    layout.vcenter(menubar(), 1.0),
		    body_
		)
	    ),
	    kit.background()
	)
    );

I am running this program on a 68k machine, using gcc 2.3.3 as the
compiler, with optimization turned on.  The compiler decided to call
kit.background() before calling the first part of the call to
Background::Background().  kit.background() returns a color with a
refcount of one.  However, the call to menubar() causes the resources
to be re-read, and the previously-read colors are unreferenced, which
causes the background to go to a reference count of zero, and it is
deleted.  However, we already have a pointer to the background that is
subsequently passed to the Background constructor (which by this time
point to something else entirely).  This problem only seems to
manifest itself with the Openlook and Motif kits (not the SMFKit), for
some reason.  The sparc version of gcc evaluates the arguments in the
opposite order, so the problem is not seen.

There are a number of ways of working around the problem in this
instance.  However, I can see the problem popping up in a number of
similar circumstances.  Any ideas about a general solution?

------------------------------------
E. Jason Scheck
jasons@tv.TV.TEK.COM
------------------------------------
Technical Details
Message-ID: <1993Jan6.214907.8429@tvnews.tv.tek.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!news.tek.com!tvnews!snoboy.tv.tek.com!jasons

Show Full Headers
Complete Article Headers
Newsgroups: comp.windows.interviews
Path: arc1-ca.pugleaf.net!sparky!uunet!news.tek.com!tvnews!snoboy.tv.tek.com!jasons
From: jasons@snoboy.tv.tek.com (Jason Scheck)
Subject: Resource life problem
Message-ID: <1993Jan6.214907.8429@tvnews.tv.tek.com>
Followup-To: comp.windows.interviews
Summary: Resource is unreffed before used in function call
Sender: news@tvnews.tv.tek.com (news user)
Organization: Tektronix Inc., Beaverton, OR
Date: Wed, 6 Jan 1993 21:49:07 GMT
Lines: 37