Skip to content

Matrix Portal M4 Network object is getting heavier #6461

Closed
@mpicker90

Description

@mpicker90

CircuitPython version

Adafruit CircuitPython 7.3.0 on 2022-05-23; Adafruit Matrix Portal M4 with samd51j19
Board ID:matrixportal_m4

adafruit-circuitpython-bundle-7.x-mpy-20220604

Code/REPL

import gc
import board
import rgbmatrix
import framebufferio
import displayio
from adafruit_display_text import bitmap_label
from adafruit_matrixportal.network import Network

print("starting mem", gc.mem_free())
bit_depth = 2
base_width = 64
base_height = 32
chain_across = 2
tile_down = 1
serpentine = True

width = base_width * chain_across
height = base_height * tile_down

addr_pins = [board.MTX_ADDRA, board.MTX_ADDRB, board.MTX_ADDRC, board.MTX_ADDRD]
rgb_pins = [
    board.MTX_R1,
    board.MTX_G1,
    board.MTX_B1,
    board.MTX_R2,
    board.MTX_G2,
    board.MTX_B2,
]
clock_pin = board.MTX_CLK
latch_pin = board.MTX_LAT
oe_pin = board.MTX_OE

displayio.release_displays()
matrix = rgbmatrix.RGBMatrix(
    width=width,
    height=height,
    bit_depth=bit_depth,
    rgb_pins=rgb_pins,
    addr_pins=addr_pins,
    clock_pin=clock_pin,
    latch_pin=latch_pin,
    output_enable_pin=oe_pin,
    tile=tile_down, serpentine=serpentine,
)
display = framebufferio.FramebufferDisplay(matrix)
print("mem after display", gc.mem_free())

group = displayio.Group()
print("mem after display group", gc.mem_free())

#update to font file on system your system
label = bitmap_label.Label(<font file>, anchor_point=(0, 0))
label.color = 0xFF0000
label.text = "hello world"
label.x = 10
label.y = 10
print("mem after label", gc.mem_free())

group.append(label)
print("mem after appending label", gc.mem_free())

display.show(group)
print("mem after display show", gc.mem_free())

network = Network(status_neopixel=board.NEOPIXEL)
print("mem after network creation", gc.mem_free())

response = network.fetch("http://example.com")
print("mem after response", gc.mem_free())

Behavior

This code initializes a display and network object and prints out free memory after each action. When upgrading from CircuitPython 7.2.0 to CircuitPython 7.3.0 i noticed the free memory is reduced by 16,000 at the start of the application. If there is no network connection import, then the free memory is roughly the same. A loss of 16k worth of free memory is quite a bit and causing my board to run out of memory on more complicated applications

Description

No response

Additional information

Running 7.2.0 without importing network prints
starting mem 112272
mem after display 103824
mem after display group 103744
mem after label 102656
mem after appending label 102656
mem after display show 102656

Running 7.3.0 without importing network prints
starting mem 112000
mem after display 103552
mem after display group 103472
mem after label 101200
mem after appending label 101200
mem after display show 101200

Running 7.2.0 with a network connection prints
starting mem 71536
mem after display 63088
mem after display group 63008
mem after label 60816
mem after appending label 60816
mem after display show 60816
mem after network creation 59648
mem after response 58400

Running 7.3.0 with a network connection prints
starting mem 55712
mem after display 47264
mem after display group 47184
mem after label 44528
mem after appending label 44528
mem after display show 44528
mem after network creation 43456
mem after response 42176

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions