Autor Beitrag
CodeRed
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Win 2000
D7 Pers
BeitragVerfasst: So 05.06.05 01:08 
hi!
Ich hab bei einem Programm eine Variable vom Typ string. Dieser weise ich in einer Schleife einige 100mal Text zu (etwas größere Mengen).
Das Problem ist nun, dass mein Programm nach dem Schleifendurchlauf bereits mehr als 80MB Ram belegt. Wenn ich die Schleife wieder durchlaufen lasse, so verdoppelt sich der belegte Speicher wieder.

gibt es einge Möglichkeit den Speicher wieder freizugeben, vielleicht sogar während dem Durchlauf??

MfG
CodeRed
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: So 05.06.05 01:13 
ausblenden Delphi-Quelltext
1:
2:
    if WinVer > WvNt then
      SetprocessWorkingSetSize(GetCurrentProcess,Cardinal(-1),Cardinal(-1));

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
CodeRed Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Win 2000
D7 Pers
BeitragVerfasst: So 05.06.05 12:38 
Da kommt bei mir: "Undefinierter Bezeichner: 'WinVer'".
Brauche ich noch eine zusätzliche Unit dafür??
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: So 05.06.05 12:48 
ausblenden Delphi-Quelltext
1:
2:
  if Win32Platform = VER_PLATFORM_WIN32_NT then
    SetProcessWorkingSetSize(GetCurrentProcess, Cardinal(-1), Cardinal(-1));

Fragt sich nur, ob damit belegter Speicher wieder freigegeben wird.

_________________
Ciao, Sprint.
CodeRed Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Win 2000
D7 Pers
BeitragVerfasst: So 05.06.05 13:27 
also der Code funktioniert nun, aber
DER SPEICHER WIRD NICHT FREIGEGEBEN!!

Gibt es keine andere Möglichkeit???
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: So 05.06.05 13:32 
ich weiss ja nicht was du mit deinem string aufführst. aber das hier sollte ihn eigentlich freimachen:
ausblenden Delphi-Quelltext
1:
setlength(mystring,0);					

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: So 05.06.05 13:32 
user profile iconSprint hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
  if Win32Platform = VER_PLATFORM_WIN32_NT then
    SetProcessWorkingSetSize(GetCurrentProcess, Cardinal(-1), Cardinal(-1));

Fragt sich nur, ob damit belegter Speicher wieder freigegeben wird.

Belegter nicht, aber unbelegter

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 05.06.05 13:34 
Vllcht mit SetLength :?: :?: :?:

_________________
Programmers never die, they just GOSUB without RETURN
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: So 05.06.05 13:49 
Wie reservierst du denn den Speicher? Zeig mal etwas Code.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: So 05.06.05 14:19 
Genau, zeig uns mal ein bisschen Code. Wahrscheinlich hast du irgendwo einen Speicherleck...
Um einen String freizugeben kannst du S := '', SetLength(S, 0) oder Finalize(S) schreiben.
CodeRed Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Win 2000
D7 Pers
BeitragVerfasst: So 05.06.05 14:49 
ok, hab nun weiter gesucht, da all eure hilfe net geholfen hat und hab nun gefunden, dass der speicher gleich bleibt, wenn ich diese 2 prozeduren weg lass:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
procedure TForm1.WB_GetDocumentSourceToStream(Document: IDispatch; Stream: TStream);
// Speichert ein Webbrowser Document in einen Stream
var
   PersistStreamInit: IPersistStreamInit;
   StreamAdapter: IStream;
begin
   // Überprüfen, ob Dokument verfügbar ist
   Assert(Assigned(Document));
   // Inhalt des Streams löschen
   Stream.Size:= 0;
   Stream.Position:= 0;
   // IPersistStreamInit - Interface des Dokuments besorgen
   if Document.QueryInterface(IPersistStreamInit,
     PersistStreamInit) = S_OK then
   begin
     // Verwende Stream-Adapter, um IStream Interface zu unserem
     // Stream zu bekommen
     StreamAdapter:= TStreamAdapter.Create(Stream, soReference);
     // Speichere Daten aus dem Dokument in den Stream
     PersistStreamInit.Save(StreamAdapter, False);
     // Streamadapter explizit zerstören
     // (optional, würde sowieso passieren, wenn
     // Routine verlassen wird)
     StreamAdapter:= nil;
   end;
end;

function TForm1.WB_GetDocumentSourceToString(Document: IDispatch): string;
// Speichert ein Webbrowser Document in einen string
var
  Stream: TStringStream;
begin
  Result := '';
  Stream := TStringStream.Create('');
  try
    WB_GetDocumentSourceToStream(Document, Stream);
    Result := Stream.Datastring;
  finally
    Stream.Free;
  end;
end;


der fehler muss also hier irgendwo liegen. ich hoffe einer von euch findet ihn!!

MfG
CodeRed

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: So 05.06.05 15:44 
probier mal statt      StreamAdapter:= nil;
ausblenden Delphi-Quelltext
1:
     StreamAdapter.free; Streamadapter := nil;					

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
CodeRed Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Win 2000
D7 Pers
BeitragVerfasst: So 05.06.05 17:21 
hmmm, StreamAdapter kennt kein Free...
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: So 05.06.05 17:27 
StreamAdapter ist ein Interface, die haben Refcounts und fegen sich selbst aus dem Speicher. Na nun, sollten sie. Wenn der Gültigkeitsbereich eines Interfaces beendet wird, fügt Delphi automatisch code ein, die den Refernzzähler ggf. erniedrigen. Ist der =0, wird das Objekt freigegeben. Bei einer Zuweisung (:=nil) geschieht das Gleiche. Normalerweise funktioniert das auch. Aber was ist bei Windows schon normal...
CodeRed Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 45

Win 2000
D7 Pers
BeitragVerfasst: So 05.06.05 19:32 
so, hab nun nach einer anderen Möglichkeit gesucht und setze nun den Quelltext so um:

seite := Form1.WebBrowser1.OleObject.Document.documentElement.innerHTML;

geht genauso und das Speicherproblem besteht nicht mehr