Discussion:
Memory leak while plot.replot
Nitish Jha
2014-07-31 16:25:51 UTC
Permalink
Hello,

i am using a CurveWidget in my application to show the position of a robot.
this is updated periodically (250ms) using a qtimer. the plot also contains
a large number of static plotitems. I have noticed that the memory usage of
the application keeps increasing every time there is a replot. (commenting
out the replot fixes the problem and remove the static plotitems from the
plot also does the same) I wanted to know if there is a way to limit the
redraws only to the robot position plot item and not the the static
background items. see images for clearer description.

any help is greatly appreciated

relevant code

def create_plot_widgets(self):
self.layout_plot_widget = CurveWidget(parent=self,title="Tank
Layout",xlabel="x [mm]",ylabel="y [mm]")
self.layout_plot_widget.plot.axes_synchronised = True
self.layout_plot_widget.register_all_curve_tools()
#self.layout_plot_widget.plot.set_as

self.robot_item = guiqwt.shapes.PolygonShape(points =
self.simulator.robot.robot_item_array)

self.robot_item.pen.setColor(QtCore.Qt.blue)
self.robot_item.pen.setWidth(3)
self.robot_item.set_selectable(False)
self.layout_plot_widget.plot.add_item(self.robot_item)


self.slofec_sensor_item_list = []
for sensor in self.simulator.sensor_list:
if sensor.sensor_type == 'virtual_slofec':
for sensor_coordinates in sensor.rotated_sensor_coordinates:
sensor_module_item = guiqwt.shapes.PolygonShape(points
= sensor_coordinates)
sensor_module_item.pen.setColor(QtCore.Qt.red)
sensor_module_item.set_selectable(False)

sensor_module_item.pen.setWidth(2)
self.slofec_sensor_item_list.append(sensor_module_item)

self.layout_plot_widget.plot.add_item(sensor_module_item)

self.tank_layout_items_list = []

for point_set in self.simulator.tank_layout:
[(x1,y1),(x2,y2)] = point_set
line_segment = guiqwt.shapes.SegmentShape(x1,y1,x2,y2)
self.tank_layout_items_list.append(line_segment)
self.layout_plot_widget.plot.add_item(line_segment)
line_segment.set_selectable(False)
line_segment.set_readonly(True)


self.layout_plot_widget.plot.replot()


#qtimer event
def plot_gui_update(self):

if self.simulator.robot!=None:


self.robot_item.set_points(self.simulator.robot.rotated_robot_item_array)
slofec_sensor = None
if len(self.slofec_sensor_item_list)!=0:
for sensor in self.simulator.sensor_list:
if sensor.sensor_type=='virtual_slofec':
slofec_sensor = sensor


if slofec_sensor!=None:
for i in range(0,len(self.slofec_sensor_item_list)):
sensor_plot_item = self.slofec_sensor_item_list[i]

sensor_plot_item.set_points(slofec_sensor.rotated_sensor_coordinates[i])
if slofec_sensor.sensor_weld_state[i]:
sensor_plot_item.pen.setColor(QtCore.Qt.green)
else:
sensor_plot_item.pen.setColor(QtCore.Qt.red)

self.layout_plot_widget.plot.replot()
--
You received this message because you are subscribed to the Google Groups "guidata/guiqwt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guidata_guiqwt+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Nitish Jha
2014-08-12 11:01:11 UTC
Permalink
i have attached a python file that one can run and you will notice that the
memory usage keeps on increasing.
Post by Nitish Jha
Hello,
i am using a CurveWidget in my application to show the position of a
robot. this is updated periodically (250ms) using a qtimer. the plot also
contains a large number of static plotitems. I have noticed that the memory
usage of the application keeps increasing every time there is a replot.
(commenting out the replot fixes the problem and remove the static
plotitems from the plot also does the same) I wanted to know if there is a
way to limit the redraws only to the robot position plot item and not the
the static background items. see images for clearer description.
any help is greatly appreciated
relevant code
self.layout_plot_widget = CurveWidget(parent=self,title="Tank
Layout",xlabel="x [mm]",ylabel="y [mm]")
self.layout_plot_widget.plot.axes_synchronised = True
self.layout_plot_widget.register_all_curve_tools()
#self.layout_plot_widget.plot.set_as
self.robot_item = guiqwt.shapes.PolygonShape(points =
self.simulator.robot.robot_item_array)
self.robot_item.pen.setColor(QtCore.Qt.blue)
self.robot_item.pen.setWidth(3)
self.robot_item.set_selectable(False)
self.layout_plot_widget.plot.add_item(self.robot_item)
self.slofec_sensor_item_list = []
for sensor_coordinates in
sensor_module_item = guiqwt.shapes.PolygonShape(points
= sensor_coordinates)
sensor_module_item.pen.setColor(QtCore.Qt.red)
sensor_module_item.set_selectable(False)
sensor_module_item.pen.setWidth(2)
self.slofec_sensor_item_list.append(sensor_module_item)
self.layout_plot_widget.plot.add_item(sensor_module_item)
self.tank_layout_items_list = []
[(x1,y1),(x2,y2)] = point_set
line_segment = guiqwt.shapes.SegmentShape(x1,y1,x2,y2)
self.tank_layout_items_list.append(line_segment)
self.layout_plot_widget.plot.add_item(line_segment)
line_segment.set_selectable(False)
line_segment.set_readonly(True)
self.layout_plot_widget.plot.replot()
#qtimer event
self.robot_item.set_points(self.simulator.robot.rotated_robot_item_array)
slofec_sensor = None
slofec_sensor = sensor
sensor_plot_item = self.slofec_sensor_item_list[i]
sensor_plot_item.set_points(slofec_sensor.rotated_sensor_coordinates[i])
sensor_plot_item.pen.setColor(QtCore.Qt.green)
sensor_plot_item.pen.setColor(QtCore.Qt.red)
self.layout_plot_widget.plot.replot()
--
You received this message because you are subscribed to the Google Groups "guidata/guiqwt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guidata_guiqwt+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Nitish Jha
2014-08-14 15:02:02 UTC
Permalink
so changing the segmentshape to a polygon shape seems to fix the issue......
Post by Nitish Jha
i have attached a python file that one can run and you will notice that
the memory usage keeps on increasing.
Post by Nitish Jha
Hello,
i am using a CurveWidget in my application to show the position of a
robot. this is updated periodically (250ms) using a qtimer. the plot also
contains a large number of static plotitems. I have noticed that the memory
usage of the application keeps increasing every time there is a replot.
(commenting out the replot fixes the problem and remove the static
plotitems from the plot also does the same) I wanted to know if there is a
way to limit the redraws only to the robot position plot item and not the
the static background items. see images for clearer description.
any help is greatly appreciated
relevant code
self.layout_plot_widget = CurveWidget(parent=self,title="Tank
Layout",xlabel="x [mm]",ylabel="y [mm]")
self.layout_plot_widget.plot.axes_synchronised = True
self.layout_plot_widget.register_all_curve_tools()
#self.layout_plot_widget.plot.set_as
self.robot_item = guiqwt.shapes.PolygonShape(points =
self.simulator.robot.robot_item_array)
self.robot_item.pen.setColor(QtCore.Qt.blue)
self.robot_item.pen.setWidth(3)
self.robot_item.set_selectable(False)
self.layout_plot_widget.plot.add_item(self.robot_item)
self.slofec_sensor_item_list = []
for sensor_coordinates in
sensor_module_item =
guiqwt.shapes.PolygonShape(points = sensor_coordinates)
sensor_module_item.pen.setColor(QtCore.Qt.red)
sensor_module_item.set_selectable(False)
sensor_module_item.pen.setWidth(2)
self.slofec_sensor_item_list.append(sensor_module_item)
self.layout_plot_widget.plot.add_item(sensor_module_item)
self.tank_layout_items_list = []
[(x1,y1),(x2,y2)] = point_set
line_segment = guiqwt.shapes.SegmentShape(x1,y1,x2,y2)
self.tank_layout_items_list.append(line_segment)
self.layout_plot_widget.plot.add_item(line_segment)
line_segment.set_selectable(False)
line_segment.set_readonly(True)
self.layout_plot_widget.plot.replot()
#qtimer event
self.robot_item.set_points(self.simulator.robot.rotated_robot_item_array)
slofec_sensor = None
slofec_sensor = sensor
sensor_plot_item = self.slofec_sensor_item_list[i]
sensor_plot_item.set_points(slofec_sensor.rotated_sensor_coordinates[i])
sensor_plot_item.pen.setColor(QtCore.Qt.green)
sensor_plot_item.pen.setColor(QtCore.Qt.red)
self.layout_plot_widget.plot.replot()
--
You received this message because you are subscribed to the Google Groups "guidata/guiqwt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guidata_guiqwt+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...