Roza
Roza

Reputation: 19

better way of coding to fix memory leak issues

i have an application which is using this a lot

<cfset SetVariable("b.vari.#c.i#",variables[c.i])>

how can simply it in better way using cf2021 now.

i tried following the urls from a website but i am not sure, they are using some [ operator which i can't get around

i tried like this

<cfset b.vari['c.i'] = variables[ci.i]>

is that above right, i am not sure about and i think the code i have written below foes not make sense, please guide if i am doing anything wrong here

Upvotes: 0

Views: 236

Answers (1)

Adrian J. Moreno
Adrian J. Moreno

Reputation: 14859

I don't think the code you're talking about could cause a Java heap space issue unless you have low memory allocation settings for the server's JVM config and an extremely high volume of requests. Are you running a single instance of the server? Multiple instances behind a load balancer?

So this code

<cfset SetVariable("b.vari.#c.i#",variables[c.i])>

is the same as

<cfset b.vari[c.i] = variables[c.i]>

is technically

<cfset variables.b.vari[c.i] = variables[c.i]>

So you're double-stacking the same data into the variables scope of the request. Dump the variables scope after that line and you'll see the same data in there twice.

<cfdump var="#variables#">

BUT, a struct and other complex objects in CF are passed by reference and not by value. So both variables should be referencing the same memory space that was taken by variables[c.i].

You might check the -Xms (initial memory allocation) and -Xmx (maximum memory allocation) settings of your CF server's jvm.confg file. You can either edit this in the JVM settings section of CF admin directly in the file of that name.

If you've never edited those values from the defaults, you might have too little memory allocated for your CF server compared to what's available to the server as a whole. It's often the case that your application's usage eventually crosses a threshold that requires you to add and allocate more RAM to the server to handle the increased load.

While you're in there, check if the server is referencing the version of Java that shipped with your CF installation. You might also be behind on the recommended current secure version of Java for your version of CF.

What are the -Xms and -Xmx parameters when starting JVM?

https://www.cfguide.io/coldfusion-administrator/server-settings-java-jvm/

Upvotes: 4

Related Questions