Monday, 15 June 2015

c++ - Releasing unneeded QImages -



c++ - Releasing unneeded QImages -

my application streams webcam images qwidget, , has no need images after they've been displayed. application runs min or 2 before giving error several dozen times , crashing:

qimage: out of memory, returning null image

the qwidget uses displayimage(qimage) method gets called several times per second. have feeling image should take pointer parameter, have no reasoning up.

how can ensure qimages released memory?

note: create images, i'm using technique described in accepted reply of question how convert opencv cv::mat qimage .

the qimage class uses implicit info sharing. excerpts doc:

many c++ classes in qt utilize implicit info sharing maximize resource usage , minimize copying. implicitly shared classes both safe , efficient when passed arguments, because pointer info passed around, , info copied if , when function writes it, i.e., copy-on-write.

a shared class consists of pointer shared info block contains reference count , data.

when shared object created, sets reference count 1. reference count incremented whenever new object references shared data, , decremented when object dereferences shared data. shared info deleted when reference count becomes zero.

implicit sharing takes place behind scenes; programmer not need worry it.

this means if pass qimage object displayimage() value new qimage created image info in first qimage not duplicated shared reference counter incremented. means if release memory first qimage object allocated need create sure both qimage objects go out of scope.

c++ qt memory

No comments:

Post a Comment