diff options
| author | 2010-02-22 17:40:46 -0600 | |
|---|---|---|
| committer | 2010-04-07 14:27:03 -0500 | |
| commit | 166bcf90720f5354d8f046d8c639ce4f75e8edcb (patch) | |
| tree | 1ec94fe723478624448f6874db3aaf563864de15 | |
| parent | be0807b3433aa884f4b45236a91d4cdefa9ffc18 (diff) | |
Only hold a weak pointer on SurfaceComposerClients
Each process maintains an array of active SurfaceComposerClient
objects, so that they can be reused as new surfaces are parceled
across. When a SurfaceComposerClient is disposed, it will remove
itself from this list. However, because the list maintains a strong
reference on the object, a reference cycle is created, and the
client is never deleted.
This patch changes the list to maintain weak pointers on the clients
instead.
Change-Id: I93dc8155fe28b4e350366a3400cdf22a8c77cdd3
| -rw-r--r-- | libs/ui/SurfaceComposerClient.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/libs/ui/SurfaceComposerClient.cpp b/libs/ui/SurfaceComposerClient.cpp index eda84eff04..764e6442a4 100644 --- a/libs/ui/SurfaceComposerClient.cpp +++ b/libs/ui/SurfaceComposerClient.cpp @@ -56,7 +56,7 @@ namespace android { // Must not be holding SurfaceComposerClient::mLock when acquiring gLock here. static Mutex gLock; static sp<ISurfaceComposer> gSurfaceManager; -static DefaultKeyedVector< sp<IBinder>, sp<SurfaceComposerClient> > gActiveConnections; +static DefaultKeyedVector< sp<IBinder>, wp<SurfaceComposerClient> > gActiveConnections; static SortedVector<sp<SurfaceComposerClient> > gOpenTransactions; static sp<IMemoryHeap> gServerCblkMemory; static volatile surface_flinger_cblk_t* gServerCblk; @@ -193,7 +193,7 @@ SurfaceComposerClient::clientForConnection(const sp<IBinder>& conn) { // scope for lock Mutex::Autolock _l(gLock); - client = gActiveConnections.valueFor(conn); + client = gActiveConnections.valueFor(conn).promote(); } if (client == 0) { @@ -361,8 +361,8 @@ void SurfaceComposerClient::openGlobalTransaction() const size_t N = gActiveConnections.size(); VERBOSE("openGlobalTransaction (%ld clients)", N); for (size_t i=0; i<N; i++) { - sp<SurfaceComposerClient> client(gActiveConnections.valueAt(i)); - if (gOpenTransactions.indexOf(client) < 0) { + sp<SurfaceComposerClient> client(gActiveConnections.valueAt(i).promote()); + if (client != 0 && gOpenTransactions.indexOf(client) < 0) { if (client->openTransaction() == NO_ERROR) { if (gOpenTransactions.add(client) < 0) { // Ooops! |