runtime errors (Memory allocation ... failed)

I was struggling with unexpected runtime errors while extending the code of a nodemcu.
after days of trial and error to isolite the problem source, I found out that the scan_results of the wifi_info text_sensor caused the problem because in my surroundings were more wifi networks than before.
I thought it could help to share this findings in case anybody else is having the same issue.

text_sensor:
  - platform: wifi_info
    ip_address:
      name: "3-ESP IP Address"
    ssid:
      name: 1-ESP Connected SSID
    mac_address:
      name: 4-ESP Mac Address
#    scan_results: # generates runtime error when too many wifi networks found (string too long!?)
#      name: 6-ESP WiFi Scan Results

After disabling the scan_result part the code was running ok again.
I tried to limit the length of the output by a lambda filter but gave up after some tests

      filters:
        - lambda: |-
          //return left(x);
          //std::string item;
          //item = x.substr(start, end - start);
          //return item;

might be somebody has a solution that would allow to use return only a left substring to avoid the problem, but I suspect that the issue happens before the filter is applied.