Skip to content

Patch/window handling#468

Merged
j9ac9k merged 5 commits intopyqtgraph:developfrom
nanoant:patch/window-handling
Jun 1, 2020
Merged

Patch/window handling#468
j9ac9k merged 5 commits intopyqtgraph:developfrom
nanoant:patch/window-handling

Conversation

@nanoant
Copy link
Copy Markdown
Contributor

@nanoant nanoant commented Apr 10, 2017

This PR reduces number of references to PyQtGraph windows implicitly hold by the package. Also removes some memory leak in ImageView.close() not taking care of self.imageItem.

This PR is related to #466

@codecov-io
Copy link
Copy Markdown

codecov-io commented Apr 10, 2017

Codecov Report

Merging #468 into develop will decrease coverage by 5%.
The diff coverage is 40.54%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #468      +/-   ##
===========================================
- Coverage    36.07%   31.07%   -5.01%     
===========================================
  Files          198      196       -2     
  Lines        27621    27220     -401     
  Branches      4582     4548      -34     
===========================================
- Hits          9964     8458    -1506     
- Misses       16779    17947    +1168     
+ Partials       878      815      -63
Impacted Files Coverage Δ
...h/graphicsItems/ViewBox/axisCtrlTemplate_pyside.py 0% <0%> (-100%) ⬇️
pyqtgraph/flowchart/FlowchartCtrlTemplate_pyqt.py 0% <0%> (ø) ⬆️
pyqtgraph/canvas/TransformGuiTemplate_pyside.py 0% <0%> (ø) ⬆️
...raphicsItems/PlotItem/plotConfigTemplate_pyside.py 0% <0%> (-100%) ⬇️
pyqtgraph/flowchart/FlowchartTemplate_pyqt5.py 0% <0%> (ø) ⬆️
pyqtgraph/flowchart/FlowchartCtrlTemplate_pyqt5.py 0% <0%> (ø) ⬆️
pyqtgraph/imageview/ImageViewTemplate_pyside.py 0% <0%> (-100%) ⬇️
.../graphicsItems/PlotItem/plotConfigTemplate_pyqt.py 0% <0%> (ø) ⬆️
pyqtgraph/canvas/TransformGuiTemplate_pyqt5.py 0% <0%> (ø) ⬆️
pyqtgraph/canvas/CanvasTemplate_pyqt5.py 0% <0%> (ø) ⬆️
... and 86 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f627a6a...d81bf21. Read the comment docs.


## Convenience functions for command-line use

plots = []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These references should be necessary to ensure the plots stay alive as long as they the user keeps them open. Perhaps we can have the references automatically removed when the window is closed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I'll try to keep the references, and remove them on window close.

@nanoant nanoant force-pushed the patch/window-handling branch 3 times, most recently from 1659f5f to d243cce Compare May 11, 2017 13:20
There is no need to wrap PlotView/ImageView into QMainWindow, since
only purpose of the QMainWindow is some default menu toolbar & menu
handling, that is not used by PyQtGraph anyway.

Moreover, every parent-less Qt widget can become window, so this
change just use PlotView/ImageView as windows, removing extra
complexity, eg. method forwarding, self.win property.

Another benefit of this change, it that these windows get initial
dimensions and titles as they were designed in .ui file.
We should not close explicitly child widgets or clear scene, otherwise
Qt will deallocate children views, and cause "wrapped C/C++ object of
type ImageItem has been deleted" error next time we call close()
and/or some other methods.

All children, including self.ui.roiPlot, self.ui.graphicsView will be
closed together with its parent, so there is no need to close them
explicitly.

So the purpose of close it to reclaim the memory, but not to make the existing ImageView object dysfunctional.
PyQtGraph images and plots module list variables are currently holding
references to all plots and image windows returned directly from main
module. This does not seem to be documented however, and causes the Qt
windows to be not released from memory, even if user releases all own
references.

This change removes the references from images/plots list once window
is closed, so when there is no other reference, window and all related
memory is reclaimed.
@nanoant nanoant force-pushed the patch/window-handling branch from d243cce to d81bf21 Compare September 26, 2017 13:09
@nanoant
Copy link
Copy Markdown
Contributor Author

nanoant commented Sep 26, 2017

@campagnola Hi I have updated my PR, but I have no idea why Travis fails with IOError: [Errno 4] Interrupted system call. I don't see any of updated code in the call-stack. Any clues?

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jun 1, 2020

Hi @nanoant sorry it's taken us so long to get to this. I fixed a merge conflict, this looks good to me. I'll be merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants