{"record":{"id":"571cce906f108278","repo":"wailsapp/wails","slug":"createstreamonhglobal-failed-with-e-outofmemory","errorCode":null,"errorMessage":"CreateStreamOnHGlobal failed with E_OUTOFMEMORY","messagePattern":"CreateStreamOnHGlobal failed with E_OUTOFMEMORY","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/pkg/w32/ole32.go","lineNumber":85,"sourceCode":"\tcase E_UNEXPECTED:\n\t\tpanic(\"CoCreateInstance failed with E_UNEXPECTED\")\n\t}\n\n\treturn HRESULT(ret)\n}\n\nfunc CreateStreamOnHGlobal(hGlobal HGLOBAL, fDeleteOnRelease bool) *IStream {\n\tstream := new(IStream)\n\tret, _, _ := procCreateStreamOnHGlobal.Call(\n\t\tuintptr(hGlobal),\n\t\tuintptr(BoolToBOOL(fDeleteOnRelease)),\n\t\tuintptr(unsafe.Pointer(&stream)))\n\n\tswitch uint32(ret) {\n\tcase E_INVALIDARG:\n\t\tpanic(\"CreateStreamOnHGlobal failed with E_INVALIDARG\")\n\tcase E_OUTOFMEMORY:\n\t\tpanic(\"CreateStreamOnHGlobal failed with E_OUTOFMEMORY\")\n\tcase E_UNEXPECTED:\n\t\tpanic(\"CreateStreamOnHGlobal failed with E_UNEXPECTED\")\n\t}\n\n\treturn stream\n}\nfunc OleInitialise() {\n\tprocOleInitialize.Call()\n}\n\nfunc RegisterDragDrop(hwnd HWND, dropTarget *DropTarget) error {\n\n\tdt := combridge.New[iDropTarget](dropTarget)\n\thr, _, _ := procRegisterDragDrop.Call(\n\t\thwnd,\n\t\tdt.Ref(),\n\t)\n","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/wailsapp/wails/blob/0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3/v3/pkg/w32/ole32.go#L67-L103","documentation":"CreateStreamOnHGlobal returned E_OUTOFMEMORY: the system could not allocate the internal stream object (or lock the global memory) because memory is exhausted. The Go wrapper panics on this HRESULT. It is an environment/resource condition, not an argument mistake.","triggerScenarios":"Large payloads placed on the clipboard or drag-drop data object on a memory-pressured machine; a leak of IStream objects (never Released) gradually exhausting the heap; committing a very large HGLOBAL.","commonSituations":"Long-running Wails processes that repeatedly build streams for clipboard/drag operations without Release(); containers or CI runners with tight memory limits; 32-bit processes hitting the 2GB address-space ceiling.","solutions":["Free memory: make sure every IStream from this path gets Release()d and the corresponding HGLOBAL is owned correctly","Reduce payload size or stream data in chunks instead of one giant HGLOBAL","Check available memory / switch to a 64-bit build if running 32-bit","Recover from the panic at the operation boundary and surface an 'out of memory' error to the user instead of crashing the app"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"var ms memoryStatus\nGlobalMemoryStatusEx(&ms)\nif ms.AvailPhys < uint64(size) {\n    return fmt.Errorf(\"insufficient memory for %d bytes\", size)\n}","typeGuard":null,"tryCatchPattern":"for attempt := 0; attempt < 2; attempt++ {\n    func() (err error) {\n        defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"stream alloc failed: %v\", r) } }()\n        stream = w32.CreateStreamOnHGlobal(h, true)\n        return\n    }()\n    if err == nil { break }\n    runtime.GC() // release unreferenced streams, then retry once\n}","preventionTips":["Release every IStream you create","Stream large payloads in chunks instead of one HGLOBAL","Prefer 64-bit builds for large clipboard/drag data"],"tags":["windows","win32","ole","out-of-memory","panic"],"backgroundTag":null,"analyzedSha":"0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3","analyzedAt":"2026-08-15T14:17:36.034Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}