Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 

Why is using "Eval" bad in production?

Wandering around these forums I have found various posts regarding use of Eval being bad. But the only issues with its use, mentioned, that I could find were

  1. It compiles the code, so is slow.

  2. When called multiple times, it leaks memory.

So I was thinking, if there is a method "RunMyApp()" that handles all the application execution workflow, and application's "Main()" is like

function Main()
RunMyApp()
end function

And I change the "Main()" to

function Main()
eval("RunMyApp()")
end function

Do the both points mentioned earlier about using Eval being the bad practice still hold? As ideally if there is no error in the call to "RunMyApp()"

  1. The code will only be compiled once.

  2. Eval will be called once so no memory leaks.

Although I will call eval again if the "RunMyApp()" encountered some error but that will be rare, so, memory leaks or compilation times still not be an issue. Basically what I want to do is keep my application running even if there is some one time error.

Also, are there any other issues other than the mentioned two?
0 Kudos
6 Replies
TheEndless
Level 7

Re: Why is using "Eval" bad in production?

"scorpiontahir02" wrote:
2. Eval will be called once so no memory leaks.

I don't know for sure, and I'm sure EnTerr will correct me on this Smiley Wink, but it was always my assumption that anything run inside of Eval would bypass garbage collection, resulting in leaks. If that is indeed the case, then it doesn't matter if you call Eval once or a 100 times, you're going to end up leaking pretty much everything in your code.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos

Re: Why is using "Eval" bad in production?

"TheEndless" wrote:
I don't know for sure, and I'm sure EnTerr will correct me on this Smiley Wink, but it was always my assumption that anything run inside of Eval would bypass garbage collection, resulting in leaks. If that is indeed the case, then it doesn't matter if you call Eval once or a 100 times, you're going to end up leaking pretty much everything in your code.

Any way to test the memory leaks? r2d2_bitmaps only displays graphics memory information and doesn't seem to be an issue there even after running the app for more than 15 hours now.
Available memory 38279104 used 720896 max 39000000
0 Kudos
TheEndless
Level 7

Re: Why is using "Eval" bad in production?

"scorpiontahir02" wrote:
Any way to test the memory leaks? r2d2_bitmaps only displays graphics memory information and doesn't seem to be an issue there even after running the app for more than 15 hours now.

"free" might give you more insight into the memory usage.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
squirreltown
Level 8

Re: Why is using "Eval" bad in production?

"TheEndless" wrote:

"free" might give you more insight into the memory usage.


Which "bucket" of memory is this measuring?, the space where the code runs? My 4200 lists 379312 as total mem., so It's definitely not graphic memory.
Kinetics Screensavers
0 Kudos

Re: Why is using "Eval" bad in production?

"TheEndless" wrote:

"free" might give you more insight into the memory usage.

Thank you very much, I will experiment with this and will post how much eval affects the memory.

On a side note, can you please give me reference/list/link to these commands? I knew only about r2d2_bitmaps. I could not found these in the docs, but these can be really helpful in development.
0 Kudos
TheEndless
Level 7

Re: Why is using "Eval" bad in production?

"scorpiontahir02" wrote:
On a side note, can you please give me reference/list/link to these commands? I knew only about r2d2_bitmaps. I could not found these in the docs, but these can be really helpful in development.

There is no publicly documented list that I'm aware of. They've just come up on this forum over the years. Aside from genkey and I think, but don't recall specifics, some ancient form of an ECP sendkeys commands, r2d2_bitmaps and free are the only ones that have been mentioned and/or documented.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos