You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After performing seemingly any type of json schema validation, it seems that memory is not being freed. For example, running this version of the example code with the cap crate to print memory usage:
use serde_json::json;
use std::alloc;
use cap::Cap;
#[global_allocator]
static ALLOCATOR: Cap<alloc::System> = Cap::new(alloc::System, usize::max_value());
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Allocated before validation: {}KB", ALLOCATOR.allocated()/1024);
{
let schema = json!({"maxLength":5});
let instance = json!("foo");
let validator = jsonschema::validator_for(&schema)?;
assert!(validator.validate(&instance).is_ok());
}
println!("Allocated after validation: {}KB", ALLOCATOR.allocated()/1024);
Ok(())
}
results in the following being printed
Allocated before validation: 0KB
Allocated after validation: 4184KB
Using the jsonschema::is_valid approach instead results in the same behavior:
println!("Allocated before validation: {}KB", ALLOCATOR.allocated()/1024);
{
let schema = json!({"maxLength":5});
let instance = json!("foo");
assert!(jsonschema::is_valid(&schema, &instance));
assert!(jsonschema::validate(&schema, &instance).is_ok());
}
println!("Allocated after validation: {}KB", ALLOCATOR.allocated()/1024);
Allocated before validation: 0KB
Allocated after validation: 4184KB
Creating a more complex schema seems to increase the memory held after the validation scope:
Allocated before validation: 0KB
Allocated after validation: 11355KB
It seems to me that the memory should be released after the program exits the scope in which jsonschema is used, but it does not. Is there an issue with how I'm doing validation here? Or is there a problem with jsonschema itself?
The text was updated successfully, but these errors were encountered:
There are a few Lazy statics that are evaluated upon first access; for example, meta schemas are needed to validate the input schemas. However, I'd think that the size of meta-schemas is always the same, maybe some other cache (like for patterns, but they are not present).
In any event, I'll take a look if there is anything which is not cleaned or not capped at least
After performing seemingly any type of json schema validation, it seems that memory is not being freed. For example, running this version of the example code with the cap crate to print memory usage:
results in the following being printed
Using the jsonschema::is_valid approach instead results in the same behavior:
Creating a more complex schema seems to increase the memory held after the validation scope:
It seems to me that the memory should be released after the program exits the scope in which jsonschema is used, but it does not. Is there an issue with how I'm doing validation here? Or is there a problem with jsonschema itself?
The text was updated successfully, but these errors were encountered: