Skip to content

Commit

Permalink
[TIMOB-26202] Fix Ti.UI.Window references
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed Jul 23, 2018
1 parent c097d7b commit d2a9f3a
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ private void cleanupSections()
{
ArrayList<TableViewSectionProxy> sections = getSectionsArray();
for (TableViewSectionProxy section : sections) {
section.releaseViews();
section.setParent(null);
}
sections.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public void releaseViews()

if (controls != null) {
for (TiViewProxy control : controls) {
control.releaseKroll();
control.releaseViews();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,19 @@ public void setOnSearchChangeListener(OnSearchChangeListener listener)
{
searchChangeListener = listener;
}

@Override
public void release()
{
if (searchView != null) {
searchView.setOnQueryTextListener(null);
searchView.setOnCloseListener(null);
searchView.setOnQueryTextFocusChangeListener(null);
searchView = null;
}
if (searchChangeListener != null) {
searchChangeListener = null;
}
super.release();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -434,19 +434,21 @@ public void setRowData(TableViewRowProxy rp)
}
}

if (props.containsKey(TiC.PROPERTY_LAYOUT)) {
content.setLayoutArrangement(TiConvert.toString(props, TiC.PROPERTY_LAYOUT));
}
if (props.containsKey(TiC.PROPERTY_HORIZONTAL_WRAP)) {
content.setEnableHorizontalWrap(TiConvert.toBoolean(props, TiC.PROPERTY_HORIZONTAL_WRAP));
}
if (content != null) {
if (props.containsKey(TiC.PROPERTY_LAYOUT)) {
content.setLayoutArrangement(TiConvert.toString(props, TiC.PROPERTY_LAYOUT));
}
if (props.containsKey(TiC.PROPERTY_HORIZONTAL_WRAP)) {
content.setEnableHorizontalWrap(TiConvert.toBoolean(props, TiC.PROPERTY_HORIZONTAL_WRAP));
}

// hasControls() means that the proxy has children
if (rp.hasControls()) {
createControls();
} else {
// no children means that this is an old-style row
refreshOldStyleRow();
// hasControls() means that the proxy has children
if (rp.hasControls()) {
createControls();
} else {
// no children means that this is an old-style row
refreshOldStyleRow();
}
}

if (ICS_OR_GREATER) {
Expand Down Expand Up @@ -655,6 +657,9 @@ public void release()
views.clear();
views = null;
}
if (item != null) {
item = null;
}
if (content != null) {
content.removeAllViews();
content = null;
Expand Down
8 changes: 5 additions & 3 deletions android/runtime/v8/src/native/JavaObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ jobject JavaObject::getJavaObject()
jobject ref = ReferenceTable::getReference(refTableKey_);
if (ref == NULL) {
// Sanity check. Did we get into a state where it was weak on Java, got GC'd but the C++ proxy didn't get deleted yet?
LOGE(TAG, "!!! OH NO! We tried to grab a Java Object back out of the reference table, but it must have been GC'd, because it's null! Key: %d", refTableKey_);
LOGW(TAG, "Could not obtain reference, java object has already been collected! (Key: %d)", refTableKey_);
DeleteJavaRef();
}
return ref;
}
Expand Down Expand Up @@ -181,7 +182,8 @@ void JavaObject::MakeJavaStrong()
jobject stored = ReferenceTable::clearReference(refTableKey_);
if (stored == NULL) {
// Sanity check. Did we get into a state where it was weak on Java, got GC'd but the C++ proxy didn't get deleted yet?
LOGE(TAG, "!!! OH NO! We tried to move a weak Java object back to strong, but it's aleady been GC'd by JVM! We're in a bad state! Key: %d", refTableKey_);
LOGW(TAG, "Could not move weak reference to strong, java object has already been collected! (Key: %d)", refTableKey_);
DeleteJavaRef();
} else {
env->DeleteLocalRef(stored);
}
Expand Down Expand Up @@ -238,12 +240,12 @@ void JavaObject::DeleteJavaRef()
} else {
env->DeleteGlobalRef(javaObject_);
}
javaObject_ = NULL;
} else {
LOGD(TAG, "Deleting ref in ReferenceTable for key: %d, pointer: %p", refTableKey_, this);
ReferenceTable::destroyReference(refTableKey_); // Kill the Java side
refTableKey_ = 0; // throw away the key
}
javaObject_ = NULL;
// When we're done we should be wrapping nothing!
ASSERT(javaObject_ == NULL);
ASSERT(refTableKey_ == 0);
Expand Down
13 changes: 7 additions & 6 deletions android/runtime/v8/src/native/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@ static void onPropertyChangedForProxy(Isolate* isolate, Local<String> property,
jobject javaValue = TypeConverter::jsValueToJavaObject(isolate, env, value, &javaValueIsNew);

jobject javaProxy = proxy->getJavaObject();
env->CallVoidMethod(javaProxy,
JNIUtil::krollProxyOnPropertyChangedMethod,
javaProperty,
javaValue);

proxy->unreferenceJavaObject(javaProxy);
if (javaProxy != NULL) {
env->CallVoidMethod(javaProxy,
JNIUtil::krollProxyOnPropertyChangedMethod,
javaProperty,
javaValue);
proxy->unreferenceJavaObject(javaProxy);
}

env->DeleteLocalRef(javaProperty);
if (javaValueIsNew) {
Expand Down
9 changes: 7 additions & 2 deletions android/runtime/v8/src/native/V8Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ Java_org_appcelerator_kroll_runtime_v8_V8Object_nativeFireEvent
emitter = TypeConverter::javaObjectToJsValue(V8Runtime::v8_isolate, env, jEmitter).As<Object>();
}

Local<Value> fireEventValue = emitter->Get(EventEmitter::emitSymbol.Get(V8Runtime::v8_isolate));
if (!fireEventValue->IsFunction()) {
Local<String> symbol = EventEmitter::emitSymbol.Get(V8Runtime::v8_isolate);
if (emitter.IsEmpty() || symbol.IsEmpty()) {
return JNI_FALSE;
}

Local<Value> fireEventValue = emitter->Get(symbol);
if (fireEventValue.IsEmpty() || !fireEventValue->IsFunction()) {
return JNI_FALSE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1571,14 +1571,19 @@ protected void onDestroy()

//LW windows
if (window == null && view != null) {
view.releaseViews();
view.release();
view = null;
}
if (view != null) {
view.releaseViews();
view = null;
}

if (window != null) {
if (windowStack.contains(window)) {
removeWindowFromStack(window);
}
window.closeFromActivity(isFinishing);
window.releaseViews();
window.releaseKroll();
window = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,10 +630,20 @@ public void releaseViews()
if (runtimeHandler != null) {
runtimeHandler = null;
}
if (mainHandler != null) {
mainHandler = null;
}
setModelListener(null);
KrollRuntime.suggestGC();
}

@Override
public void release()
{
releaseViews();
super.release();
}

/**
* Implementing classes should use this method to create and return the appropriate view.
* @param activity the context activity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,4 +525,32 @@ protected boolean hasActivityTransitions()
final boolean animated = TiConvert.toBoolean(getProperties(), TiC.PROPERTY_ANIMATED, true);
return (LOLLIPOP_OR_GREATER && animated && sharedElementPairs != null && !sharedElementPairs.isEmpty());
}

@Override
public void releaseViews()
{
if (view != null) {
if (children != null) {
for (TiViewProxy p : children) {
p.releaseViews();
}
}
view = null;
}
if (tab != null) {
tab.releaseViews();
tab = null;
}
if (tabGroup != null) {
tabGroup.releaseViews();
tabGroup = null;
}
if (runtimeHandler != null) {
runtimeHandler = null;
}
if (mainHandler != null) {
mainHandler = null;
}
setModelListener(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ public void remove(TiUIView child)
child.parent = null;
}
}
if (child.getProxy() != null) {
child.getProxy().releaseViews();
}
}
}

Expand Down

0 comments on commit d2a9f3a

Please sign in to comment.