Claude Code Plugins

Community-maintained marketplace

Feedback

mojo-memory-check

@mvillmow/ml-odyssey
4
0

Verify memory safety in Mojo code including ownership, borrowing, and lifetime management. Use when reviewing code or debugging memory issues.

Install Skill

1Download skill
2Enable skills in Claude

Open claude.ai/settings/capabilities and find the "Skills" section

3Upload to Claude

Click "Upload skill" and select the downloaded ZIP file

Note: Please verify skill by going through its instructions before using it.

SKILL.md

name mojo-memory-check
description Verify memory safety in Mojo code including ownership, borrowing, and lifetime management. Use when reviewing code or debugging memory issues.

Memory Safety Check Skill

Verify Mojo code follows memory safety rules.

When to Use

  • Reviewing code for memory safety
  • Debugging memory issues
  • Before merging code
  • Performance testing reveals issues

Memory Ownership

Owned Parameters

fn consume(owned data: Tensor):
    # Takes ownership, original is invalidated
    process(data)
    # data is destroyed here

Borrowed Parameters

fn read_only(borrowed data: Tensor):
    # Read-only access, no ownership transfer
    let value = data[0]
    # data still valid in caller

Inout Parameters

fn modify(inout data: Tensor):
    # Mutable reference
    data[0] = 42
    # Changes visible in caller

Common Issues

1. Use After Move

# ❌ Wrong
fn bad():
    let data = Tensor()
    consume(data^)  # Move ownership
    print(data[0])  # Error: data moved!

# ✅ Correct
fn good():
    let data = Tensor()
    let copy = data  # Copy if needed
    consume(data^)
    print(copy[0])  # OK

2. Lifetime Issues

# ❌ Wrong
fn return_dangling() -> borrowed Tensor:
    let local = Tensor()
    return local  # Returns reference to local!

# ✅ Correct
fn return_owned() -> Tensor:
    let local = Tensor()
    return local^  # Move ownership

3. Mutable Aliasing

# ❌ Wrong
fn alias_problem(inout a: Tensor, borrowed b: Tensor):
    a[0] = b[0]  # If a and b alias, undefined!

# ✅ Correct
fn no_alias(inout a: Tensor, borrowed b: Tensor):
    # Ensure a and b don't alias
    if a.ptr() != b.ptr():
        a[0] = b[0]

Checklist

  • No use-after-move
  • No dangling references
  • No mutable aliasing
  • Proper lifetime management
  • Ownership clear and documented

See Mojo ownership documentation for details.