Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UForm causing memory leak #1081

Closed
ronenteva opened this issue Dec 9, 2023 · 2 comments · Fixed by #1185
Closed

UForm causing memory leak #1081

ronenteva opened this issue Dec 9, 2023 · 2 comments · Fixed by #1185
Labels
bug Something isn't working

Comments

@ronenteva
Copy link

Environment

  • Operating System: Windows_NT
  • Node Version: v20.10.0
  • Nuxt Version: 3.8.2
  • CLI Version: 3.10.0
  • Nitro Version: 2.8.1
  • Package Manager: pnpm@8.12.0
  • Builder: -
  • User Config: modules, ui, devtools
  • Runtime Modules: @nuxt/ui@2.11.0
  • Build Modules: -

Version

v2.11.0

Reproduction

app.vue:

<script setup lang="ts">
import type { FormError, FormSubmitEvent } from '#ui/types'

const state = reactive({
  email: undefined,
  password: undefined
})

const validate = (state: any): FormError[] => {
  const errors = []
  if (!state.email) errors.push({ path: 'email', message: 'Required' })
  if (!state.password) errors.push({ path: 'password', message: 'Required' })
  return errors
}

async function onSubmit (event: FormSubmitEvent<any>) {
  // Do something with data
  console.log(event.data)
}
</script>

<template>
  <UForm :validate="validate" :state="state" class="space-y-4" @submit="onSubmit">
    <UFormGroup label="Email" name="email">
      <UInput v-model="state.email" />
    </UFormGroup>

    <UFormGroup label="Password" name="password">
      <UInput v-model="state.password" type="password" />
    </UFormGroup>

    <UButton type="submit">
      Submit
    </UButton>
  </UForm>
</template>

a simple logger for memory usage /server/plugins/memory.js:

export default defineNitroPlugin(nitroApp => {
  let maxUsage = 0;
  setInterval(() => {
    const memoryUsage = process.memoryUsage();
    if (memoryUsage.heapUsed > maxUsage) {
      maxUsage = memoryUsage.heapUsed;
      console.log(`Heap Used: ${Math.round(memoryUsage.heapUsed / 1024 / 1024 * 100) / 100} MB`);
    }
  }, 1000);
});

run autocannon http://localhost:3000 -f to see the memory usage going up and up

Description

Seems that any usage of <UForm/> is causing memory leak.

Additional context

No response

Logs

No response

@ronenteva ronenteva added the bug Something isn't working label Dec 9, 2023
Copy link
Member

@romhml Any idea about this?

@romhml romhml mentioned this issue Jan 2, 2024
8 tasks
@romhml
Copy link
Collaborator

romhml commented Jan 2, 2024

I managed to find two different cause: one is the ever-growing counter in useUid and the other is the form's event listeners not being cleared. I fixed both in #1185.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants