diff --git a/examples/scriptableapplication/mainwindow.cpp b/examples/scriptableapplication/mainwindow.cpp
index 26d80a7de..ddf01929c 100644
--- a/examples/scriptableapplication/mainwindow.cpp
+++ b/examples/scriptableapplication/mainwindow.cpp
@@ -24,6 +24,7 @@ using namespace Qt::StringLiterals;
 static const auto defaultScript = R"(import AppLib
 print("Hello, world")
 mainWindow.testFunction1()
+print(mainWindow.style())
 )"_L1;
 
 MainWindow::MainWindow()
diff --git a/sources/pyside6/PySide6/glue/qtwidgets.cpp b/sources/pyside6/PySide6/glue/qtwidgets.cpp
index e6c835d3b..e039038b9 100644
--- a/sources/pyside6/PySide6/glue/qtwidgets.cpp
+++ b/sources/pyside6/PySide6/glue/qtwidgets.cpp
@@ -521,14 +521,17 @@ Shiboken::Object::keepReference(reinterpret_cast<SbkObject *>(%PYSELF), "__style
 
 // @snippet qwidget-style
 QStyle *myStyle = %CPPSELF->style();
+qDebug() << __FUNCTION__ << myStyle << qApp;
 if (myStyle && qApp) {
 %PYARG_0 = %CONVERTTOPYTHON[QStyle *](myStyle);
     QStyle *appStyle = qApp->style();
     if (appStyle == myStyle) {
+        qDebug() << __FUNCTION__ << "appStyle == myStyle/setParent";
         Shiboken::AutoDecRef pyApp(%CONVERTTOPYTHON[QApplication *](qApp));
         Shiboken::Object::setParent(pyApp, %PYARG_0);
         Shiboken::Object::releaseOwnership(%PYARG_0);
     } else {
+        qDebug() << __FUNCTION__ << "appStyle != myStyle/keepReference";
         Shiboken::Object::keepReference(reinterpret_cast<SbkObject *>(%PYSELF), "__style__",  %PYARG_0);
     }
 }
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp
index 8d722f6e4..8ce84e699 100644
--- a/sources/shiboken6/libshiboken/basewrapper.cpp
+++ b/sources/shiboken6/libshiboken/basewrapper.cpp
@@ -1201,17 +1201,24 @@ void releaseOwnership(SbkObject *self)
 {
     // skip if the ownership have already moved to c++
     auto *selfType = Py_TYPE(self);
-    if (!self->d->hasOwnership || Shiboken::Conversions::pythonTypeIsValueType(PepType_SOTP(selfType)->converter))
+    std::cerr << __FUNCTION__ << ' '  << Shiboken::debugSbkObject(self) << '\n';
+    if (!self->d->hasOwnership || Shiboken::Conversions::pythonTypeIsValueType(PepType_SOTP(selfType)->converter)) {
+        std::cerr << __FUNCTION__  << " bail\n";
         return;
+    }
+    std::cerr << __FUNCTION__ << ' '  << Shiboken::debugSbkObject(self) << "  containsCppWrapper=" << self->d->containsCppWrapper << '\n';
 
     // remove object ownership
     self->d->hasOwnership = false;
 
     // If We have control over object life
-    if (self->d->containsCppWrapper)
+    if (self->d->containsCppWrapper) {
+        std::cerr << __FUNCTION__ << " incref\n";
         Py_INCREF(reinterpret_cast<PyObject *>(self)); // keep the python object alive until the wrapper destructor call
-    else
+    } else {
+        std::cerr << __FUNCTION__ << " inval\n";
         invalidate(self); // If I do not know when this object will die We need to invalidate this to avoid use after
+    }
 }
 
 void releaseOwnership(PyObject *self)
@@ -1231,6 +1238,7 @@ void invalidate(PyObject *pyobj)
 
 void invalidate(SbkObject *self)
 {
+    std::cerr << __FUNCTION__ << ' '  << Shiboken::debugSbkObject(self) << '\n';
     std::set<SbkObject *> seen;
     recursive_invalidate(self, seen);
 }
@@ -1587,6 +1595,8 @@ void setParent(PyObject *parent, PyObject *child)
     bool parentIsNull = !parent || parent == Py_None;
     auto parent_ = reinterpret_cast<SbkObject *>(parent);
     auto child_ = reinterpret_cast<SbkObject *>(child);
+    std::cerr << __FUNCTION__ <<  ' ' << Shiboken::debugSbkObject(parent_) << ' '
+              << Shiboken::debugSbkObject(child_) << '\n';
 
     if (!parentIsNull) {
         if (!parent_->d->parentInfo)
@@ -1598,7 +1608,11 @@ void setParent(PyObject *parent, PyObject *child)
     }
 
     ParentInfo *pInfo = child_->d->parentInfo;
-    bool hasAnotherParent = pInfo && pInfo->parent && pInfo->parent != parent_;
+    auto *op = pInfo ? pInfo->parent : nullptr;
+    bool hasAnotherParent = op && op != parent_;
+    std::cerr << __FUNCTION__ <<  " hasAnotherParent=" << hasAnotherParent
+              << ' ' << Shiboken::debugSbkObject(op)
+              << '\n';
 
     //Avoid destroy child during reparent operation
     Py_INCREF(child);
