[Magma] leftover sessions and more

Chris Muller afunkyobject at yahoo.com
Wed Aug 27 22:16:28 UTC 2003


This is strange!  I went ahead and created a script to recreate this problem. 
It reminded me of a couple of things that have bitten me in the past that may
help.

But first, let me comment on your prior:

> Here are the things I did (all are class methods of AdmApp)
> 
> ----------------------------------------
> (1) delete the existing database files (MagmaSessions=19)
> 
> ----------------------------------------
> (2) Create a new repository via: 
> newDatabase
> 	^ MagmaRepositoryController create: self databaseFile root:
> 	Dictionary new
> 
> at this point I am not sure if I am already connected or not. So I
> open a session via

Perfect.  Creating is just a utility method, it does not leave you connected.


> connect
> 	self isConnected
> 		ifTrue: [^ self inform: 'aleady connected'].
> 	magmaSession _ MagmaSession openLocal: self databaseFile.
> 	magmaSession connectAs: 'martin'

Perfect.

> (MagmaSessions now has 21 instances)

No way!  These instances are certainly old, before you created this latest
repository.  Opening a repository creates two new Sessions, period.  No way 21
were created from this.

Please make sure your MagmaSession allInstances size reports 0 before you
start.


> ----------------------------------------
> (3) Then I tried to add a collection via
> 
> createItemCollection
> 	| itemCollection |
> 	itemCollection _ MagmaCollection new.
> 	magmaSession
> 		commit: [self dbRoot at: #itemCollection put: itemCollection].
> 	itemCollection
> 		addIndex: (MaSearchStringIndexDefinition attribute: #name keySize: 64)

You must commit the adding of the index.  Also, this reminds me;
MagmaCollections reference their "transient" variables using
MaVirualInstVarContainer.  In this case, the session is required transient
information for the MagmaCollection to function.  Check out the package "Ma
dynamic instance variables" in a package-pane browser for more info.

It uses weak collections so it's not something you need to be concerned with,
and is NOT the cause of these hanging instances, but it's a good thing to know.


> dbRoot
> 	^ magmaSession root

You are correct not to cache the root, good.  Magma tip:  never cache the root
for a long time in your program, or objects will not get garbage collected and
performance will slow to a crawl.


> a file 2066911.hdx  is created

This is the *membership* index for the collection.  As you can see, however,
your #2066911name.hdx didn't get created because you didn't commit (above).

> ----------------------------------------
> (4) Here comes the silly part: I try to disconnect with
> ...
> disconnectAll
> 	MagmaSession allInstances
> 		do: [:each | each disconnect; closeRepository].
> 	MagmaRepositoryController allInstances
> 		do: [:each | each close]
> 
> Now I have 21 Magma sessions and no way of getting rid of them. I
> tried the same with just sending a 
>         AdmApp magmaSession disconnect; closeRepository 
> and the number of instances drops back to its original value, but my
> silly disconnectAll seems to leave 2 dangling instances.

This disconnectAll method is not necessary at all.  You are cleaning up
properly in your disconnect method with one exception.  You are not cleaning up
your proxies.  Proxies *do* reference their session so they can read from the
correct repository when they need to.

Currently, it is YOUR responsibility to get rid of any dangling proxies after
you disconnect.  Perhaps I should put it in the disconnect method, but I hate
to do that because it takes a long time (not as long as it took for me to track
this down again though!).

  MaOdbmsProxy allInstances do: [ : each | each become: String new ]

Unfortunately, I can think of no better way to handle this!

I thought this was your solution.  However, I created the following script
based on your code to make sure:

	Transcript cr; show: MagmaSession allInstances size printString, ' instances
of MagmaSession before test.'.
	filename _ 'c:\temp\', x printString, '.magma'.
	MagmaRepositoryController create: filename root: Dictionary new.
	s _ MagmaSession openLocal: filename.
	s connectAs: 'martin'.
	s commit: [ s root at: x put: MagmaCollection new ].
	s commit: [ (s root at: x) addIndex: (MaSearchStringIndexDefinition attribute:
#name keySize: 64) ].
	s disconnect; closeRepository.
	MaOdbmsProxy allInstances do: [ : each | each become: String new ].
	Smalltalk garbageCollect.
	Transcript cr; show: MagmaSession allInstances size printString, ' instances
of MagmaSession after test.'.

In running this, it still said there were two instances of MagmaSession.  Rats!

Inspecting these two instnaces and using "chase pointers" reveals empty window
as if there are no references.  But using "objects pointing to this value"
reveals MethodContext objects pointing, even though I have no processes with
any Magma code running (which I verified by looking at the Process browser).

Why are these MethodContexts keeping the old values around?  Efficiency?  I
would like an answer to this question from someone in the Squeak community who
knows.  If so, perhaps the only solution, then, is to get rid of them ourself;
what a disappointment!

  MagmaSession allInstances do: [ : each | each become: String new ]

This is a new phonomena to me!  If you get any ideas, let me know.  I'll do the
same.

Regards,
  Chris

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com



More information about the Squeak-dev mailing list