{"record":{"id":"753454619d38129c","repo":"emberjs/ember.js","slug":"cannot-create-new-instances-after-the-owner-has-be","errorCode":null,"errorMessage":"Cannot create new instances after the owner has been destroyed (you attempted to create ${this.fullName})","messagePattern":"Cannot create new instances after the owner has been destroyed \\(you attempted to create (.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@ember/-internals/container/lib/container.ts","lineNumber":535,"sourceCode":"    this.fullName = fullName;\n    this.normalizedName = normalizedName;\n    this.madeToString = undefined;\n    this.injections = undefined;\n  }\n\n  toString(): string {\n    if (this.madeToString === undefined) {\n      this.madeToString = this.container.registry.makeToString(this.class, this.fullName);\n    }\n\n    return this.madeToString;\n  }\n\n  create(options?: Partial<T>) {\n    let { container } = this;\n\n    if (container.isDestroyed) {\n      throw new Error(\n        `Cannot create new instances after the owner has been destroyed (you attempted to create ${this.fullName})`\n      );\n    }\n\n    let props = options ? { ...options } : {};\n    setOwner(props, container.owner!);\n    setFactoryFor(props, this);\n\n    if (DEBUG) {\n      let lazyInjections;\n      let validationCache = this.container.validationCache;\n      // Ensure that all lazy injections are valid at instantiation time\n      if (\n        !validationCache[this.fullName] &&\n        this.class &&\n        typeof this.class._lazyInjections === 'function'\n      ) {\n        lazyInjections = this.class._lazyInjections();","sourceCodeStart":517,"sourceCodeEnd":553,"githubUrl":"https://github.com/emberjs/ember.js/blob/26f97246a8bf2e28edf26ac3093da2e86c04ffc5/packages/@ember/-internals/container/lib/container.ts#L517-L553","documentation":"FactoryManager#create refuses to instantiate new objects once the owning container is destroyed. Even though a factory reference may survive teardown, creating instances from it would produce objects bound to a dead owner.","triggerScenarios":"Calling factoryFor(...).create() after the owner was destroyed — typically in async callbacks, Ember.run.later callbacks, or retained references used post-teardown.","commonSituations":"Retaining a factory manager and creating records/services after test teardown; fastboot shutdown mid-request; app.destroy() while background sync code still creates objects.","solutions":["Create instances before teardown or guard with container/owner isDestroyed checks","Cancel pending async work in willDestroy","In tests, await settled() before teardown","Rearchitect to get instances injected rather than created imperatively later"],"exampleFix":"// before\nlater = run.later(() => this.store.createRecord('user'), 1000);\n// after\nlater = run.later(() => {\n  if (!this.isDestroying) this.store.createRecord('user');\n}, 1000);","handlingStrategy":"validation","validationCode":"if (this.isDestroying || this.isDestroyed) return; let obj = Factory.create(props);","typeGuard":"function canCreate(owner) { return !owner.isDestroyed && !owner.isDestroying; }","tryCatchPattern":"try { return Factory.create(props); } catch (e) { if (String(e.message).includes('Cannot create new instances after the owner has been destroyed')) return null; throw e; }","preventionTips":["Create instances during normal lifecycle, not post-teardown","Cancel deferred work in willDestroy","Prefer injection over imperative create()","Use settled() in tests before teardown"],"tags":["ember","lifecycle","factory-manager","create"],"backgroundTag":"lookup-after-destroy","analyzedSha":"26f97246a8bf2e28edf26ac3093da2e86c04ffc5","analyzedAt":"2026-09-01T05:01:28.182Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}