6

I usually like PHP, because it is easy to use, but FUCK! Can you just let me free the fucking memory by myself? Setting variable to null doesn't work, unset doesn't work either. I am still getting fucking memory exhausted error.
There is literally no data stored anywhere, because I unset every fucking thing.
gc_collect_cycles() doesn't work either, probably because this crap thinks there is a reference for this variable somewhere.

Comments
  • 2
    Memory limit set to 256MB, memory_get_usage() returns 85MB at max, wtf is going on here?
  • 1
    And now it reports 419MB somehow wut??!!
  • 1
    fucking hell man, I am legit interesting in the kind of stuff you is doing with this amd wondering if the configuration needs to happen somewhere else outside of the script itself. Are you doing something that would benefit from some concurrency? The thing is the higher your memory the less number of concurrent process you would get.

    Let me get @C0D4
  • 0
    @AleCx04 I'm indexing a shit ton of data. The data alone is not that big, but the parsing process takes a bit more memory. I already had to create my own index format, because the resulting index couldn't be parsed into JSON with less than 1GB of memory :D It worked fine until I added thing that I call "byte map". Also it looks like, it's not really my mistake, but there are some issues with gc in PHP FPM.
  • 3
    Unset() is exactly what you want.

    Are you using variables as reference "&var" or value?

    If your using values then each variable is copying and creating a new source of memory usage.
    By reference is a single allocation of memory dropped into a containing method.

    Unsetting or setting to null will clear it if you catch them all.

    Otherwise increase the memory allocation limit in .ini to be able to utilise enough for what you are doing.

    Or use ini_set("memory_limit", 500M);
    For a temporary increase of memory,

    You can use 0 and it will allow any memory resources but not always a good idea.

    Care to share the code in a gist? I Can try and help.
  • 1
    @lamka02sk Can you use a non-gc language and call it from PHP by any chance?
  • 1
    @Lor-inc Unfortunately, it is supposed to run (at least temporarily) on shared hosting, so there is not much of a choice. Trust me, I wouldn't use PHP for this if I could.

    @C0D4 Sorry, I can't share source with you as it is not my personal project. I am using &$var whenever possible. After some debugging, the main problem seems to be our database library. It returns array of objects, but these objects seems to be never garbage collected.
  • 1
    @lamka02sk Can you unset the DB connection and have the GC collect it along with all that data?
  • 0
    Fuck it, I will try to ask colleague tomorrow. Hopefully, he will come up with something...
  • 0
    @lamka02sk that's fine.
    I'd increase the memory as much as possible then by the sounds of things, or query less data at a time and work in a batch kind of process. It will be slower but you'll churn through it all.
  • 0
    I think there might be a problem in the db lib. Never had an issue like this. Can't you ditch it?
  • 0
    You cant control the GC and you shouldn't try to. Just make sure that you dont have ANY live references to the variable you dont need and it will be freed on the next GC cycle.
    Also PHP is doing copy on write so using &$var makes your code slower if you are not modifying the variable.
Add Comment