Best use case
77-webgl-jslib-memory-rules is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Status: ACTIVE
Teams using 77-webgl-jslib-memory-rules should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/77-webgl-jslib-memory-rules/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How 77-webgl-jslib-memory-rules Compares
| Feature / Agent | 77-webgl-jslib-memory-rules | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Status: ACTIVE
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 77-webgl-jslib-memory-rules
Status: ACTIVE
AppliesTo: v10
Type: Policy / Hard Rules
---
## Purpose
WebGL `.jslib` ↔ C# 간 ptr/len/문자열 메모리 수명 규칙을 **Hard Rule**로 고정한다.
이 규칙을 위반하면 **메모리 누수 또는 크래시**가 발생한다.
---
## Hard Rules
### 1. `.jslib`가 `_malloc`한 모든 버퍼는 C#이 반드시 Free 호출로 반환해야 함
| 이벤트 | 포인터 | Free 함수 |
|--------|--------|-----------|
| MESSAGE | `dataPtr` | `WS_FreeBuffer(dataPtr)` |
| ERROR/CLOSE | `messagePtr` | `WS_FreeString(messagePtr)` |
**위반 시**: WASM heap 메모리 누수 → 장기 실행 시 OOM 크래시
### 2. C#은 `WS_PollEvent`로 받은 ptr을 즉시 managed(ArrayPool)로 복사하고 ptr을 보존하지 않는다
```csharp
// CORRECT
var buffer = ArrayPool<byte>.Shared.Rent(dataLen);
Marshal.Copy(dataPtr, buffer, 0, dataLen);
// ... 사용 ...
ArrayPool<byte>.Shared.Return(buffer);
WS_FreeBuffer(dataPtr);
// WRONG - ptr 보존 금지
_savedPtr = dataPtr; // 이후 Free 시점 불명확 → 누수/UAF
```
**위반 시**: Use-After-Free 또는 메모리 누수
### 3. 한 Tick에서 처리 가능한 이벤트 개수 상한이 있어야 한다
```csharp
const int MaxEventsPerTick = 64; // 권장값
for (int i = 0; i < MaxEventsPerTick; i++)
{
if (WS_PollEvent(...) == 0)
break;
// 처리
}
```
**위반 시**: 대량 수신 시 프레임 드롭, 메인 스레드 블로킹
### 4. `ToArray()` 금지, `ArrayPool<byte>` 사용 강제
```csharp
// CORRECT
var buffer = ArrayPool<byte>.Shared.Rent(dataLen);
Marshal.Copy(dataPtr, buffer, 0, dataLen);
// ... 사용 후 ...
ArrayPool<byte>.Shared.Return(buffer);
// WRONG
byte[] buffer = new byte[dataLen]; // GC 압박
Marshal.Copy(dataPtr, buffer, 0, dataLen);
```
**위반 시**: GC 압박으로 프레임 스파이크, 핫 경로 allocation
---
## 권장 구현 패턴
### MESSAGE 처리
```csharp
case EventType.MESSAGE:
// 1. ArrayPool에서 버퍼 임대
var buffer = ArrayPool<byte>.Shared.Rent(dataLen);
try
{
// 2. Marshal.Copy로 복사
Marshal.Copy(dataPtr, buffer, 0, dataLen);
// 3. core로 전달
_core.OnFrame(_sessionId, buffer.AsSpan(0, dataLen));
}
finally
{
// 4. ArrayPool 반환
ArrayPool<byte>.Shared.Return(buffer);
}
// 5. Free 호출 (반드시)
WS_FreeBuffer(dataPtr);
break;
```
### ERROR/CLOSE 처리
```csharp
case EventType.CLOSE:
string reason = "";
if (messagePtr != IntPtr.Zero)
{
reason = Marshal.PtrToStringUTF8(messagePtr);
WS_FreeString(messagePtr); // 반드시
}
EnqueueDispatch(() => OnClose?.Invoke((ushort)code, reason));
break;
```
---
## FAIL 조건
아래 패턴이 문서/코드에 등장하면 **FAIL**:
1. **Free 누락 가능성이 있는 설계**
- 예: `dataPtr`를 필드에 저장하고 나중에 Free하는 구조
- 예: 예외 발생 시 Free가 호출되지 않는 코드 경로
2. **`ToArray()` 또는 `new byte[]` 사용**
- 핫 경로(수신 루프)에서 allocation
3. **이벤트 처리량 상한 없음**
- 무한 루프로 PollEvent 호출
4. **ptr 보존**
- `WS_PollEvent`에서 받은 ptr을 복사 없이 보관
---
## Verification Checklist
- [ ] MESSAGE 수신 후 `WS_FreeBuffer(dataPtr)` 호출됨
- [ ] ERROR/CLOSE 수신 후 messagePtr이 non-null이면 `WS_FreeString(messagePtr)` 호출됨
- [ ] 예외 발생 시에도 Free가 호출되도록 try-finally 또는 동등한 구조 사용
- [ ] `ArrayPool<byte>.Shared.Rent()`/`.Return()` 사용
- [ ] `ToArray()` 또는 `new byte[]` 미사용
- [ ] Tick당 이벤트 처리 상한 존재 (권장: 64)
---
## Reference
- 폴링 계약: [76-webgl-ws-polling-bridge](../76-webgl-ws-polling-bridge/SKILL.md)
- WebSocket 클라이언트: [72-network-ws-client](../72-network-ws-client/SKILL.md)Related Skills
advanced-memory-skill-creator
Use when planning, scaffolding, validating, or packaging Claude skills inside Advanced Memory MCP.
admin-interface-rules
Rules for the Admin interface functionalities
adf-validation-rules
Comprehensive Azure Data Factory validation rules, activity nesting limitations, linked service requirements, and edge-case handling guidance
accessibility-rules
Concise accessibility checklist and practices for components in the repository. Use when implementing UI to ensure keyboard, screen reader, and focus semantics.
ac-memory-manager
Manage persistent memory for autonomous coding. Use when storing/retrieving knowledge, managing Graphiti integration, persisting learnings, or accessing episodic memory.
monad-memory
π/τ-tier. Structure, navigation, closure (~500 tokens). Navigation between skills. Decimal: π.8.0. Load via: φ→π
76-webgl-ws-polling-bridge
Status: ACTIVE
32-example-webgl-server — Unity WebGL 서버 가이드
Status: ACTIVE
ontopo
An AI agent skill to search for Israeli restaurants, check table availability, view menus, and retrieve booking links via the Ontopo platform, acting as an unofficial interface to its data.
modal-deployment
Run Python code in the cloud with serverless containers, GPUs, and autoscaling using Modal. This skill enables agents to generate code for deploying ML models, running batch jobs, serving APIs, and scaling compute-intensive workloads.
astro
This skill provides essential Astro framework patterns, focusing on server-side rendering (SSR), static site generation (SSG), middleware, and TypeScript best practices. It helps AI agents implement secure authentication, manage API routes, and debug rendering behaviors within Astro projects.
tech-blog
Generates comprehensive technical blog posts, offering detailed explanations of system internals, architecture, and implementation, either through source code analysis or document-driven research.