Open CASCADE, the 3D modelling kernel
3D modeling & numerical simulation

Search the Forums
See All Topics
Open CASCADEShowroomGet it!Developer CornerSupport and ProductsAbout us
Technical overview
Areas of use
Shape factory
Shape gallery
What's new
System requirements
Download Center
Public license
Getting started
Open Source community
Training and e-learning
A-la Carte Support
Value-added software
Complementary Components
Customer Corner
Company Profile
Marketing Materials
Contact Us
Home / Developer Corner / Forums / Usage issues / How to de-allocate memory of a QT-OCC view?

How to de-allocate memory of a QT-OCC view?

How to de-allocate memory of a QT-OCC view?
punz markus 2012/11/15 14:57
I am working with Qt 4.7.3 and OCC 6.5.3.
I have a problem with memory-management or maybe I just misunderstand OCC-Handles?

My application needs to create and destroy OCC windows many times, we are able to float and split the windows everything seems to work fine except that we are not able to release even 1KB of the views memory...
Here is some code from a simplifyed testView ... it's based on the Qt_occ examples.

TestViewOCC::TestViewOCC(QWidget * parent, LDSDoc * document)
     : QWidget(parent), LDSView(document), currentAction(CA_NOTHING) , rotCenter(0.0, 0.0, 0.0), degenerateMode(true), firstPaint(true)
     , occDefaultDevice(nullptr), occViewer(nullptr), occView(nullptr), occContext(nullptr),localContextIndex(-1),occOvlLayer(nullptr), hWnd(nullptr), s_factor(0.0), tw_factor(0.0)//, mouseLast(NULL), rotScrCent(NULL)
     ,backgroundColor(Quantity_Color(.200, .200, .400, Quantity_TOC_RGB)), mouseLast(0.0,0.0), rotScrCent(0.0,0.0), eyex(0.0), eyey(0.0), eyez(0.0), viewx(0.0), viewy(0.0), viewz(0.0),

     occDefaultDevice=new Graphic3d_WNTGraphicDevice();
     TCollection_ExtendedString viewName("LDSGeom3DView");
     occViewer=new V3d_Viewer(occDefaultDevice, viewName.ToExtString(), (Standard_CString)"", 1000., V3d_XposYnegZpos,
          backgroundColor.Name(),V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT, Standard_True, Standard_True, V3d_TEX_NONE);
     //occViewer->SetZBufferManagment( Standard_False );

     occViewer->SetLightOff(); // NOTE tbam: we have to turn all lights off because we don't want the default lightsource!     

     occContext=new AIS_InteractiveContext(occViewer);     
     setAttribute(Qt::WA_WState_Visible, false);

          occView = occViewer->CreateView();


and the paint method

void TestViewOCC::paintEvent(QPaintEvent * e)
               occView = occViewer->CreateView();

               hWnd = new WNT_Window(Handle(Graphic3d_WNTGraphicDevice)::DownCast(occViewer->Device()), winId());



               occView->SetDegenerateModeOn();      //obsolete
               occView->SetDegenerateModeOff();      //obsolete
          occOvlLayer=new Visual3d_Layer(occViewer->Viewer(), Aspect_TOL_OVERLAY, Standard_False);
          s_factor = occView->Scale();
} you can see, we're working with OCC handles all the time (maybe we shouldn't do that?).
The problem now is that (even if I try to nullify all of these handles in the view) no memory seems to be released when the view is closed.

     // I just tried sth....


     ... and much more

     //no changes at all, nothing changes even if we reduce the view to the minimum (no context, no Visual3d_Layer..., only a V3d_Viewer, a V3d_View and the hWnd)

When I try to debug, f.e. the destructor of WNT_Window is called (even if I don't nullify) , but the DestroyWindow()-function is NEVER called, why?

void WNT_Window :: Destroy ()
     if ( !( myExtraData.dwFlags & WDF_FOREIGN ) ) /// dwFlags is always 3 ->     
           DestroyWindow ( ( HWND )myHWindow ); /// IS NEVER REACHED !      

Note that the hWnd handles refCount is up to 3 already after calling the constructor (hWnd = new WNT_Window(Handle(Graphic3d_WNTGraphicDevice)::DownCast(occViewer->Device()), winId());)
But I guess that this is usual.

What am I doing wrong? Any hints?

I wondering the qt-occ example does work exactly the same way...
So with these example views it seems that we are not able to release any of a occ-views resources until we close the application. Why?
Does someone have experience with Qt-OCC views and how to release the memory correct?

Thanks, max
punz markus 2012/11/30 12:42
I solved some of our memory issues by following Lygin's hint, to use const Handle(AIS_...)& instead of plain Handle(AIS_...)
whenever possible.

I changed the handle usage only for our AIS_InteractiveObject - dervied classes so far, and their resources now get freed and returned to the system when a view (with displayed objects) is closed...

The views resources itself are still not freed, but memory consumption increases in a passable range now.
The first opened Qt-OCC view takes about 26 MB and each additional view about 5 MB.
I tried to set the window flags of the WNT_Windows myExtraData.dwFlags and got the DestroyWindow (...) function called, but this did not lead to a benefit(Furthermore the bigger part of the memory is reserved during V3d_View->setWindow()...).

The best results I received with MMGT_OPT 1, MMGT_CLEAR 1 and MMGT_REENTRANT 0, using TBB (MMGT_OPT 1 and MMGT_REENTRANT 1) lead us to a higher consumption, furthermore we don't use multithreading so far...
MMGT_THRESHOLD did not have big influence on the few tests I did, so for now we use default value here...

A problem still exists is the load/save mechanism. F.e. IGES-loading leads to a untendable memory leak. I tried to solve it again following Lygin blog:
But without success so far.

Maybe someone has a clean example-code of loading an IGES-file without leaks?
Anyway I will post the solution when solved...
Latest news
  • Open CASCADE Technology 6.7.0 is available for download!
  • Open CASCADE Technology 6.6.0 is available for download!
  • Open CASCADE Technology 6.5.5 is available for download!

  • © OPEN CASCADE 2000 - 2014  |  Search  |  Contacts   |  Site map