How to free memory from an openstreet map

I am creating a website, and one of the scripts uses a map in openstreetmap and leaflet, my problem is that after loading that script with the map, I run out of memory when opening one other specific script.

I tried clearing the cache, and unsetting variables, but the problem remains.

If I raise the memory in php.ini everything works just fine, but I can’t do that, i need to somehow free some memory since raising memory size is not a option unfortunantely.

EDIT: After i used memory_get_usage() and memory_get_peak_usage() on the script that does not fully load this was returned

The script is now using: 195728KB of memory. Peak usage: 238372KB of memory.

It seems I was wrong to assume that the error was from the map, I apologize for my mistake.