0

My overall issue is clearing memory. The issue is now split into two sections. First is unreleased memory used by a 'for' loop. I used memory_profiler to line by line see the memory usage. the lines in question are:

For the overall loop

Line #    Mem usage    Increment   Line Contents
================================================  

1266    275.6 MiB    171.9 MiB           for i in range(0, NumMeasurements):

For the inner port-switching loop

1323    188.7 MiB     82.7 MiB           for g in range(int(self.start_port1),int(self.stop_port1)+1):

Is there a way to 'release' this memory after the respective loop is complete? Is there a better way to implement this loop? Am I understanding this correctly? I run this code and after 4 hours my RAM is up by 5 GBs!

Second part is releasing referenced memory. exhibit A, is this line

1481    186.3 MiB     79.9 MiB               self.figure = Figure(figsize = (5,3.72))

I have tried plt.close(self.figure), gc.collect(), and del self.figure. None seem to release that memory. conversely, this line seemed to release memory.

1471    198.9 MiB    -70.0 MiB                   ref_phase = self.xpS21plot['port'+ str(1)]

--OP Update--

The part that is doing the plotting is this:

 ######All Phase Reference Statements
        self.figure = Figure(figsize = (5,3.72))
        self.figure.gca().grid(True)
        self.figure.gca().set_ylabel('Magnitude')
        self.figure.gca().set_xlabel('Freq (MHz)')
        self.figure.gca().set_title('Magnitude (current)')
        #self.figure.gca().set_ylim(-80,20)
        self.axes = self.figure.add_subplot(111)
        self.canvas = FCW(self.panel1, -1, self.figure)
        #Figure.set_xlabel(self.figure, 'oops')
        # Start plot Mag setup
        for k in range(int(self.start_port1),int(self.start_port1) + len(self.magS21)):
            self.axes.plot(self.yplot['port' + str(k)],self.xS21plot['port'+ str(k)])
Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321
C H
  • 11

0 Answers0