Open zhangjiayu139 opened 4 years ago
This is a really odd way to do this. as JSON is actually being deprecated in favor of grails-views. That being said I use as JSON often and have never seen it get stuck in memory like this. It would seem something else is likely holding onto a reference of your object. Or maybe something cyclical exists in your map.
The stack implies an instanced closure may be sticking around as well yet your sample code contains no closures
@davydotcom I'm using it in Service, to turn the object into a Map and add other property values,I'm confused, too
@zhangjiayu139 you could use JsonViewTemplateEngine
instead of as JSON
. See http://views.grails.org/latest/#_the_jsontemplateengine
However, in the production environment variables are not recycled(GC)
I don't understand what you mean. Is it the case that every time you do the conversion, a new instance of middol.utils.DomainUtils$_domainListFormat_closure1
is being allocated and never collected? If not, what is it that isn't being garbage collected? Thanks for any feedback!
Thanks for reporting an issue for Grails framework, please review the task list below before submitting the issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.
NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (http://stackoverflow.com/tags/grails) or Slack (http://slack-signup.grails.org). DO NOT use the issue tracker to ask questions.
Defines a utils class, Used to convert domain instances into Map, The following code:
public static def domainFormat(domain) { def result = domain as JSON try{ return (Map)JSON.parse(result.toString()) }catch(e){ e.printStackTrace() } }
However, in the production environment variables are not recycled(GC),This often results in full memory and FULL CPU, Grab the stack memory of the production environment and analyze all points to this public methodTask List
Steps to Reproduce
public static def domainFormat(domain) { def result = domain as JSON try{ return (Map)JSON.parse(result.toString()) }catch(e){ e.printStackTrace() } }
Expected Behaviour
Tell us what should happen
Actual Behaviour
Tell us what happens instead
Environment Information
Example Application