How to fix Malloc returns null error or Calloc returns null error?

Anyone knows what’s causing this error and how to fix it?
Malloc returns null: len=131072 in BLI_Mempool Chunk, total 3750692560
Error: EXCEPTION_ACCESS_VIOLATION

I have i7, 32G Ram (24G available), Quadro M1200 & Intel HD, I don’t think it should cause a memory issue. Maybe there’s some preference I should set to have Blender use all of my available memory?

What are the steps to get this error ?

The error message means that an attempt to allocate a continuous block of memory of the given size failed. The key bit (heh) here being the continuous part. Your system monitor may show lots of free memory, but if it is chopped up into lots of little pieces, that trying to malloc a big chuck can fail

Right. It mostly happens when I run a python script, but It’s fine when I run the code line by line.
For example, the following code (on a 1mil verts mesh) would cause a memory error, or Blender just hangs. But if I just do the equivalent UI operations or run the code line by line, it’ll be fine.

import bpy
import bmesh
for obj in bpy.context.scene.objects:
    if obj.type == "MESH":
        obj.select_set(True)
        bpy.context.view_layer.objects.active = obj
        me = bpy.context.object.data
        bm = bmesh.new()
        bm.from_mesh(me)
        bpy.ops.object.mode_set(mode = 'EDIT')
        bpy.ops.mesh.reveal()
        bpy.ops.mesh.select_all(action='DESELECT')
        bpy.context.tool_settings.mesh_select_mode = (False, False, True)
        bpy.ops.mesh.select_face_by_sides(number=4, type='GREATER',extend=True)
        bpy.ops.mesh.quads_convert_to_tris(quad_method='BEAUTY', ngon_method='BEAUTY')
        bpy.ops.object.mode_set(mode='OBJECT')

Why are you creating a BMesh if you’re not using it, and not releasing it? If I had to guess, that could well be a contributing factor to (if not the source of) your problem. From the code it doesn’t look like you need it at all. But if it’s just an excerpt from larger code, seeing the way you’re creating it out of edit mode, perhaps add a bm.free() at the end.

You should use bmesh operators. Also, I think you can just use modifiers for that… finally, Meshlab may be a better choice for batch-processing meshes.