use of java.lang.ref.WeakReference in project Klyph by jonathangerbaud.
the class UploadPhotoService method onCreate.
@Override
public void onCreate() {
HandlerThread thread = new HandlerThread("ServiceStartArguments", android.os.Process.THREAD_PRIORITY_BACKGROUND);
thread.start();
mServiceLooper = thread.getLooper();
mServiceHandler = new ServiceHandler(mServiceLooper, new WeakReference<Service>(this));
}
use of java.lang.ref.WeakReference in project quasar by puniverse.
the class ActorTest method testWatchGC.
@Test
public void testWatchGC() throws Exception {
Assume.assumeFalse(Debug.isDebug());
final Actor<Message, Void> actor = spawnActor(new BasicActor<Message, Void>(mailboxConfig) {
@Override
protected Void doRun() throws SuspendExecution, InterruptedException {
Fiber.sleep(120000);
return null;
}
});
System.out.println("actor1 is " + actor);
WeakReference wrActor2 = new WeakReference(spawnActor(new BasicActor<Message, Void>(mailboxConfig) {
@Override
protected Void doRun() throws SuspendExecution, InterruptedException {
Fiber.sleep(10);
final Object watch = watch(actor.ref());
// unwatch(actor, watch);
return null;
}
}));
System.out.println("actor2 is " + wrActor2.get());
for (int i = 0; i < 10; i++) {
Thread.sleep(10);
System.gc();
}
Thread.sleep(2000);
assertEquals(null, wrActor2.get());
}
use of java.lang.ref.WeakReference in project roboguice by roboguice.
the class MapBinderTest method testWeakKeySet_integration_mapbinder.
// Tests for com.google.inject.internal.WeakKeySet not leaking memory.
public void testWeakKeySet_integration_mapbinder() {
Key<Map<String, String>> mapKey = Key.get(new TypeLiteral<Map<String, String>>() {
});
Injector parentInjector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(String.class).toInstance("hi");
}
});
WeakKeySetUtils.assertNotBlacklisted(parentInjector, mapKey);
Injector childInjector = parentInjector.createChildInjector(new AbstractModule() {
@Override
protected void configure() {
MapBinder<String, String> binder = MapBinder.newMapBinder(binder(), String.class, String.class);
binder.addBinding("bar").toInstance("foo");
}
});
WeakReference<Injector> weakRef = new WeakReference<Injector>(childInjector);
WeakKeySetUtils.assertBlacklisted(parentInjector, mapKey);
// Clear the ref, GC, and ensure that we are no longer blacklisting.
childInjector = null;
WeakKeySetUtils.awaitClear(weakRef);
WeakKeySetUtils.assertNotBlacklisted(parentInjector, mapKey);
}
use of java.lang.ref.WeakReference in project roboguice by roboguice.
the class OptionalBinderTest method testWeakKeySet_integration.
// Tests for com.google.inject.internal.WeakKeySet not leaking memory.
public void testWeakKeySet_integration() {
Injector parentInjector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(String.class).toInstance("hi");
}
});
WeakKeySetUtils.assertNotBlacklisted(parentInjector, Key.get(Integer.class));
Injector childInjector = parentInjector.createChildInjector(new AbstractModule() {
@Override
protected void configure() {
OptionalBinder.newOptionalBinder(binder(), Integer.class).setDefault().toInstance(4);
}
});
WeakReference<Injector> weakRef = new WeakReference<Injector>(childInjector);
WeakKeySetUtils.assertBlacklisted(parentInjector, Key.get(Integer.class));
// Clear the ref, GC, and ensure that we are no longer blacklisting.
childInjector = null;
WeakKeySetUtils.awaitClear(weakRef);
WeakKeySetUtils.assertNotBlacklisted(parentInjector, Key.get(Integer.class));
}
use of java.lang.ref.WeakReference in project roboguice by roboguice.
the class WeakKeySetTest method testWeakKeySet_integration.
public void testWeakKeySet_integration() {
Injector parentInjector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(Integer.class).toInstance(4);
}
});
assertNotBlacklisted(parentInjector, Key.get(String.class));
Injector childInjector = parentInjector.createChildInjector(new AbstractModule() {
@Override
protected void configure() {
bind(String.class).toInstance("bar");
}
});
WeakReference<Injector> weakRef = new WeakReference<Injector>(childInjector);
assertBlacklisted(parentInjector, Key.get(String.class));
// Clear the ref, GC, and ensure that we are no longer blacklisting.
childInjector = null;
awaitClear(weakRef);
assertNotBlacklisted(parentInjector, Key.get(String.class));
}
Aggregations