Comments (11)
Btw, this was also the case in last version I just didn't notice it until yesterday when eventually it crashed.
from qt.
Hey
Yes it's currently leaking memory, because I haven't really worked on that issue yet.
But here are a few things you can do to minimize the memory usage:
- Use the binary in
deploy/windows_minimal/
, which should also be much smaller in size. - Always try to set a proper parent (if possible), when creating a new object with
NewQ*()
. - If you regularly create and discard objects, try to destroy them with
DeleteLater()
orDestroyQ*()
once you don't need them anymore.
from qt.
Thank you. I'll keep an eye out for these cases.
from qt.
I worked on the memory leaks 1693c80
This should hopefully fix most of them.
from qt.
Wow. That's a huge amount of work! I look forward to testing it out - thank you!
from qt.
I didn't notice any change in memory consumption. Testing on Table example, tabbing through, entering data all keep increasing memory.
from qt.
Hey
I made two new commits 57465bf and 2f211fc which should also reduce the memory consumption / fix memory leaks.
If I keep adding and removing 30 rows to the table example the ram usage stays around 15mb.
I also tested your graph app and the ram usage goes up to 50mb if I keep adding and removing 30 rectangles.
Tested this on Win 7 x64 with 8gb ram and go 1.7
Can you give me some example code where your app crashes because you run out of memory?
from qt.
Looks like you updated 2 hours ago. I am commenting on the code I downloaded yesterday:
It certainly uses less memory. At one point I could see it stabilize between 25 and 30 mb.
It's crashing consistently now though after about 15 rectangles. I am pretty sure it's the same code I was using before. On the older compiles the memory would increase to over a gb in about 5 minutes but wouldn't crash as consistently as it does now.
This is code very similar to what I uploaded to github. I do not explicitly destroy objects. However, the memory increases as the mouse moves over the canvas without creating any objects.
Edit: Same behavior with new code. Once it hits 35mb it drops down to 25mb then shortly after crashes.
Adding no rectangles to scene it hangs out around 21mb. Cursoring over the canvas increases memory but it seems to garbage collect this.
Adding one rectangle and cursoring around increases memory to up to 28mb and back down to 24mb.
A third rectangle increases this shortly to 36mb then back down to 24mb.
Adding about 6 rectangles slowly, it crashes. It also crashes adding 13 rectangles quickly. It seems once it goes past the 38mb point it crashes (because it doesn't garbage collect quickly enough?). Also noticing that the more objects on the canvas, the higher the memory leak as I move the cursor. So if no rectangles, the memory increases by a few K at a time. If there are multiple rectangles on the canvas, as I move the mouse the memory increases by megabytes over the same distance.
from qt.
Sorry I added a few wrong runtime.SetFinalizers to some class constructors, which also included the QGaphicsItems and QTreeWidgetItem class and that probably caused the crashes.
But I fixed that with this commit c4e5523
I also looked into the graph app code again and made a few changes
https://github.com/therecipe/AM/commit/1c8d3bd4656beb0bd670c08dcfb501647f14c326
Instead of scene.RemoveItem()
you should use DestroyQGraphicsItem
, because this will remove the item and also destroys them instead of just removing them from the scene.
I also removed the unnecessary scene.Repaint()
functions (especially in the scene.MouseMoveEvent
function, which was consuming a lot of memory)
You should also always try to use scene.Update()
instead of scene.Repaint()
because, it is more efficient and won't force the repainting of all items.
And code that get executed a lot, like the ConnectMouseMoveEvent
or ConnectPaint
functions should be created carefully to avoid unnecessary garbage.
Hope it works now :)
from qt.
Hi tr, thanks for your help. It's working much better now.
Things I noticed:
- Adding rectangle does not increase memory.
- Moving cursor around canvas still increases memory for some reason.
- Picking up and moving a rectangle is the largest memory hog. I have been able to go from 30mb to 80mb by moving the rectangle around the canvas. Fortunately gc kicks in after 2-5sec and it goes back down to 30mb.
I added over 50 nodes and there was no crash. Average mem use was ~30mb. Max mem use was ~80mb for a short time.
I do wonder why memory increases in the mouseMoveEvent since at this point all it uses is PrepareGeometryChange(). I commented out PrepareGeometryChange() and this did not change any of the effects on memory use. Maybe this is just a qt canvas thing. I have no experience otherwise with it.
It seems to be very stable now :) Thank you for all your hard work!
from qt.
Hey, thank you :)
It seems like the big part of the memory consumption comes from the *.Paint()
functions.
The PrepareGeometryChange()
functions just seem to call the *.BoundingRect()
implementations.
I made a few changes in the *.Paint()
functions and the memory consumption went down a little.
But after I removed the SetViewportUpdateMode()
function, the memory consumption for the drag and drop operation halved. (From ~3mb steps to ~1.5mb steps)
So it still goes up to ~80mb and then cuts down to ~30mb, but slower.
https://github.com/therecipe/AM/commit/21416545b12ffb0d671a2fc9eafab3029722ef9e
I also tried to remove the background grid and the memory consumption for the drag and drop operations went down to ~0.5mb steps.
But it was acting glitchy, probably because of the missing calls to Update()
or due the new/default ViewportUpdateMode
.
So you probably could reduce the memory consumption even further if you use Scene. SetBackgroundBrush()
(with the Qt::CrossPattern BrushStyle or with some custom style) and also with QGraphicsView::CacheBackground
.
But I haven't tested this.
from qt.
Related Issues (20)
- Hello! I have a problem
- deploying linux to windows build fail with newqwebengineview. thanks for your help HOT 4
- Is alive? HOT 1
- Issue with using *QFileDialog.SelectedFiles(), "interface conversion: interface {} is []interface {}, not []string" HOT 1
- /usr/bin/ld: i386 architecture of input file `/tmp/go-link-3590783856/000000.o' is incompatible with i386:x86-64 output HOT 2
- Is there an active fork of this project? HOT 8
- android APK crashes when launched
- Installation fails for Qt 6 HOT 2
- !!! Read before opening a new issue !!!
- qtdeploy may not work with Go1.20 HOT 1
- go: warning: "github.com/therecipe/qt/cmd/..." matched no packages HOT 1
- menu.Actions() panics
- How to add a property sheet file to Qt
- How can I deploy a program to an arm development board and don't see a good way
- Intermittent Qtdeploy Failures HOT 1
- Gave up - Docs need some work for new people HOT 1
- is this project still maintains, what's the latest qt version does it support HOT 2
- qtsetup fails
- qtsetup error in freebsd 14.1 HOT 1
- New and working linux_static deployment dockerfile
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qt.