Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 08-20-2018, 05:17 PM
FreakaZoid2 FreakaZoid2 is offline
Senior Member
 
Join Date: Jul 2009
Posts: 330
Default how to free a resourcestream created inline

Currently i am using the following to create a ResourceStream and to free it up.
var
_strlist : tstringlist;
RS : TResourceStream;
begin
....

_tstrlist.Clear;
RS := (TResourceStream.Create(hInstance, 'Code_Base', 'Code'));
RS.Position := 0;
_tstrlist.LoadFromStream(RS);
RS.Free;
....
but i am wondering how do i free up the resourcestream using this command
....

_tstrlist.Clear;
_tstrlist.LoadFromStream(TResourceStream.Create(hI nstance, 'Code_Base', 'Code'));
....
Using the latter code is simple in code but i always get a resourcestream leak.
  #2  
Old 08-20-2018, 05:36 PM
rojam rojam is offline
Senior Member
 
Join Date: Jun 2015
Posts: 190
Default

Quote:
Originally Posted by FreakaZoid2 View Post
Currently i am using the following to create a ResourceStream and to free it up.
var
_strlist : tstringlist;
RS : TResourceStream;
begin
....

_tstrlist.Clear;
RS := (TResourceStream.Create(hInstance, 'Code_Base', 'Code'));
RS.Position := 0;
_tstrlist.LoadFromStream(RS);
RS.Free;
....
but i am wondering how do i free up the resourcestream using this command
....

_tstrlist.Clear;
_tstrlist.LoadFromStream(TResourceStream.Create(hI nstance, 'Code_Base', 'Code'));
....
Using the latter code is simple in code but i always get a resourcestream leak.
I suppose you can use "Smart Pointers" to create an Interface. That way, when the Interface goes out of reference, it is automatically garbage collected. You can look an an implementation of a smart pointer here.
  #3  
Old 08-20-2018, 06:00 PM
FreakaZoid2 FreakaZoid2 is offline
Senior Member
 
Join Date: Jul 2009
Posts: 330
Default Interesting...

but i was trying to figure out a way to keep the number of lines of code down instead of using more.
And thanks for the link. might come in handy for some other projects i am dealing with.
  #4  
Old 08-21-2018, 12:39 AM
rojam rojam is offline
Senior Member
 
Join Date: Jun 2015
Posts: 190
Default

Since you don't keep a reference to the resoucestream in your shortened approach, there's no way to free it.
  #5  
Old 08-21-2018, 01:53 PM
FreakaZoid2 FreakaZoid2 is offline
Senior Member
 
Join Date: Jul 2009
Posts: 330
Default that is what i needed to know.

the is not a way to create inline and not have a memory leak.


Thanks
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 01:46 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.