AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Algorithmen, Datenstrukturen und Klassendesign [Spring-DI] MemoryLeak bei Einsatz von DelegatedConstructor
Thema durchsuchen
Ansicht
Themen-Optionen

[Spring-DI] MemoryLeak bei Einsatz von DelegatedConstructor

Ein Thema von neo4a · begonnen am 1. Feb 2012 · letzter Beitrag vom 1. Feb 2012
 
Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.052 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#4

AW: [Spring-DI] MemoryLeak bei Einsatz von DelegatedConstructor

  Alt 1. Feb 2012, 13:54
Zitat:
What happens is that a local variable is added to the current routine which contains the address of the method or function pointer, and then this local variable is captured by a hidden anonymous method. This hidden anonymous method is kept alive for the duration of the current routine by a second local variable, of type IInterface (this prevents premature disposal).

The trouble is that with unit initialiaztion, and program begin/end, and similar top-level blocks, "local" variables are in fact global variables.
D.h. das "object behind the scene" (dcWallpaper$43200$ActRec), welches hinter der anonymen Methode sitzt (wir erinnern uns: eine Anonyme Methode ist eigentlich nix anderes als eine Interface Methode mit nen bisschen compiler magic) wird im Falle der Benutzung in initialization (auch in finalization oder in der "main" der dpr) in der globalen Variable gespeichert. Lagerst du aber den Code, welchen du zuvor direkt unter initialization hattest in eine Routine aus, wird die Variable lokal in der Routine angelegt. Somit ist sie nicht mehr global, da sie einen kleineren Scope hat (nämlich den der Routine) und du hast auch kein Memleak mehr.

Das hat imho überhaupt nichts mit der Verwaltung des vom DI Container erzeugten Objekts zu tun.
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:41 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz