[Kde-pim] FolderCollection objects created all the time

David Faure faure at kde.org
Fri Aug 5 11:46:17 BST 2011


FolderCollection objects are created and destroyed all the time, due to the code below:

149│ bool ReadableCollectionProxyModel::acceptRow( int sourceRow, const QModelIndex &sourceParent) const
150│ {
151│   const QModelIndex modelIndex = sourceModel()->index( sourceRow, 0, sourceParent );
152│
153│   const Akonadi::Collection collection = sourceModel()->data( modelIndex, Akonadi::EntityTreeModel::CollectionRole 
).value<Akonadi::Collection>();
154│   if ( d->hideVirtualFolder ) {
155│     if ( Util::isVirtualCollection( collection ) )
156│       return false;
157│   }
158│   if ( d->hideSpecificFolder ) {
159├>    QSharedPointer<FolderCollection> col = FolderCollection::forCollection( collection );
160│     if ( col && col->hideInSelectionDialog() )
161│       return false;
162│   }

Line 159 calls the method below:

 43│ static QMap<Collection::Id,QWeakPointer<FolderCollection> > fcMap;
 46│ QSharedPointer<FolderCollection> FolderCollection::forCollection( const Akonadi::Collection& coll )
 47│ {
 48│   QMutexLocker lock( &mapMutex ); 
 49│
 50│   QSharedPointer<FolderCollection> sptr = fcMap.value( coll.id() ).toStrongRef();
 51│
 52│   if ( !sptr ) {
 53├>    sptr = QSharedPointer<FolderCollection>( new FolderCollection( coll, true ) );
 54│     fcMap.insert( coll.id(), sptr );
 55│   }
 56│   return sptr;
 57│ }

The collecton is created and put into a map, but it's shared pointer. So as soon as it goes
out of scope (line 162), the refcount is 0 again, and it's deleted.

The issue is that it's a map of weak pointers, so it doesn't hold any ref.

Therefore, this code keeps creating and deleting foldercollection objects, which is a rather
bad since the constructor calls readConfig() which reads a whole bunch of kconfig settings.
Fortunately there is no parsing going on (KernelIf->config() stays around), but it gets quite
confusing when debugging the read of settings, to see that it's called -so- many times
(in this example it's called from acceptRow of a proxy...).

Should the map hold references, i.e. keep these objects alive forever?
I guess the issue would then become updating of the stored settings when the kconfig is changed?

The alternative would be that somehow the proxy holds a ref on all the collections it
deals with, but I guess it lives as long as kmail anyway, so this amounts to the same.

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Sponsored by Nokia to work on KDE, incl. Konqueror (http://www.konqueror.org).

_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/


More information about the kde-pim mailing list